@@ -17,397 +17,397 @@ |
||
17 | 17 | */ |
18 | 18 | class GetPaid_Admin_Setup_Wizard { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string Current Step |
|
22 | - */ |
|
23 | - protected $step = ''; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string|false Previous Step |
|
27 | - */ |
|
28 | - protected $previous_step = ''; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string|false Next Step |
|
32 | - */ |
|
33 | - protected $next_step = ''; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var array All available steps for the setup wizard |
|
37 | - */ |
|
38 | - protected $steps = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * Class constructor. |
|
42 | - * |
|
43 | - * @since 2.4.0 |
|
44 | - */ |
|
45 | - public function __construct() { |
|
46 | - |
|
47 | - if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | - add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | - add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
50 | - } |
|
51 | - |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Add admin menus/screens. |
|
56 | - * |
|
57 | - * @since 2.4.0 |
|
58 | - */ |
|
59 | - public function add_menu() { |
|
60 | - add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Sets up the setup wizard. |
|
65 | - * |
|
66 | - * @since 2.4.0 |
|
67 | - */ |
|
68 | - public function setup_wizard() { |
|
69 | - |
|
70 | - if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
71 | - $this->setup_globals(); |
|
72 | - $this->maybe_save_current_step(); |
|
73 | - $this->display_wizard(); |
|
74 | - exit; |
|
75 | - } |
|
76 | - |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Sets up class variables. |
|
81 | - * |
|
82 | - * @since 2.4.0 |
|
83 | - */ |
|
84 | - protected function setup_globals() { |
|
85 | - $this->steps = $this->get_setup_steps(); |
|
86 | - $this->step = $this->get_current_step(); |
|
87 | - $this->previous_step = $this->get_previous_step(); |
|
88 | - $this->next_step = $this->get_next_step(); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Saves the current step. |
|
93 | - * |
|
94 | - * @since 2.4.0 |
|
95 | - */ |
|
96 | - protected function maybe_save_current_step() { |
|
97 | - if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
98 | - call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Returns the setup steps. |
|
104 | - * |
|
105 | - * @since 2.4.0 |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - protected function get_setup_steps() { |
|
109 | - |
|
110 | - $steps = array( |
|
111 | - |
|
112 | - 'introduction' => array( |
|
113 | - 'name' => __( 'Introduction', 'invoicing' ), |
|
114 | - 'view' => array( $this, 'setup_introduction' ), |
|
115 | - 'handler' => '', |
|
116 | - ), |
|
117 | - |
|
118 | - 'business_details' => array( |
|
119 | - 'name' => __( "Business Details", 'invoicing' ), |
|
120 | - 'view' => array( $this, 'setup_business' ), |
|
121 | - 'handler' => '', |
|
122 | - ), |
|
123 | - |
|
124 | - 'currency' => array( |
|
125 | - 'name' => __( 'Currency', 'invoicing' ), |
|
126 | - 'view' => array( $this, 'setup_currency' ), |
|
127 | - 'handler' => '', |
|
128 | - ), |
|
129 | - |
|
130 | - 'payments' => array( |
|
131 | - 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
132 | - 'view' => array( $this, 'setup_payments' ), |
|
133 | - 'handler' => array( $this, 'setup_payments_save' ), |
|
134 | - ), |
|
135 | - |
|
136 | - 'recommend' => array( |
|
137 | - 'name' => __( 'Recommend', 'invoicing' ), |
|
138 | - 'view' => array( $this, 'setup_recommend' ), |
|
139 | - 'handler' => '', |
|
140 | - ), |
|
141 | - |
|
142 | - 'next_steps' => array( |
|
143 | - 'name' => __( 'Get Paid', 'invoicing' ), |
|
144 | - 'view' => array( $this, 'setup_ready' ), |
|
145 | - 'handler' => '', |
|
146 | - ), |
|
147 | - |
|
148 | - ); |
|
149 | - |
|
150 | - return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
151 | - |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Returns the current step. |
|
156 | - * |
|
157 | - * @since 2.4.0 |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - protected function get_current_step() { |
|
161 | - $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
162 | - return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Returns the previous step. |
|
167 | - * |
|
168 | - * @since 2.4.0 |
|
169 | - * @return string|false |
|
170 | - */ |
|
171 | - protected function get_previous_step() { |
|
172 | - |
|
173 | - $previous = false; |
|
174 | - $current = $this->step; |
|
175 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
176 | - if ( $current === $step ) { |
|
177 | - return $previous; |
|
178 | - } |
|
179 | - |
|
180 | - $previous = $step; |
|
181 | - } |
|
182 | - |
|
183 | - return false; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Returns the next step. |
|
188 | - * |
|
189 | - * @since 2.4.0 |
|
190 | - * @return string|false |
|
191 | - */ |
|
192 | - protected function get_next_step() { |
|
193 | - |
|
194 | - $on_current = false; |
|
195 | - $current = $this->step; |
|
196 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
197 | - |
|
198 | - if ( $on_current ) { |
|
199 | - return $step; |
|
200 | - } |
|
201 | - |
|
202 | - if ( $current === $step ) { |
|
203 | - return $on_current = true; |
|
204 | - } |
|
205 | - |
|
206 | - } |
|
207 | - |
|
208 | - return false; |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Displays the setup wizard. |
|
213 | - * |
|
214 | - * @since 2.4.0 |
|
215 | - */ |
|
216 | - public function display_wizard() { |
|
217 | - $this->display_header(); |
|
218 | - $this->display_current_step(); |
|
219 | - $this->display_footer(); |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Displays the Wizard Header. |
|
224 | - * |
|
225 | - * @since 2.0.0 |
|
226 | - */ |
|
227 | - public function display_header() { |
|
228 | - $steps = $this->steps; |
|
229 | - $current = $this->step; |
|
230 | - $next_step = $this->next_step; |
|
231 | - array_shift( $steps ); |
|
232 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Displays the content for the current step. |
|
237 | - * |
|
238 | - * @since 2.4.0 |
|
239 | - */ |
|
240 | - public function display_current_step() { |
|
241 | - ?> |
|
20 | + /** |
|
21 | + * @var string Current Step |
|
22 | + */ |
|
23 | + protected $step = ''; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string|false Previous Step |
|
27 | + */ |
|
28 | + protected $previous_step = ''; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string|false Next Step |
|
32 | + */ |
|
33 | + protected $next_step = ''; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var array All available steps for the setup wizard |
|
37 | + */ |
|
38 | + protected $steps = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * Class constructor. |
|
42 | + * |
|
43 | + * @since 2.4.0 |
|
44 | + */ |
|
45 | + public function __construct() { |
|
46 | + |
|
47 | + if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | + add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | + add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
50 | + } |
|
51 | + |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Add admin menus/screens. |
|
56 | + * |
|
57 | + * @since 2.4.0 |
|
58 | + */ |
|
59 | + public function add_menu() { |
|
60 | + add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Sets up the setup wizard. |
|
65 | + * |
|
66 | + * @since 2.4.0 |
|
67 | + */ |
|
68 | + public function setup_wizard() { |
|
69 | + |
|
70 | + if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
71 | + $this->setup_globals(); |
|
72 | + $this->maybe_save_current_step(); |
|
73 | + $this->display_wizard(); |
|
74 | + exit; |
|
75 | + } |
|
76 | + |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Sets up class variables. |
|
81 | + * |
|
82 | + * @since 2.4.0 |
|
83 | + */ |
|
84 | + protected function setup_globals() { |
|
85 | + $this->steps = $this->get_setup_steps(); |
|
86 | + $this->step = $this->get_current_step(); |
|
87 | + $this->previous_step = $this->get_previous_step(); |
|
88 | + $this->next_step = $this->get_next_step(); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Saves the current step. |
|
93 | + * |
|
94 | + * @since 2.4.0 |
|
95 | + */ |
|
96 | + protected function maybe_save_current_step() { |
|
97 | + if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
98 | + call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Returns the setup steps. |
|
104 | + * |
|
105 | + * @since 2.4.0 |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + protected function get_setup_steps() { |
|
109 | + |
|
110 | + $steps = array( |
|
111 | + |
|
112 | + 'introduction' => array( |
|
113 | + 'name' => __( 'Introduction', 'invoicing' ), |
|
114 | + 'view' => array( $this, 'setup_introduction' ), |
|
115 | + 'handler' => '', |
|
116 | + ), |
|
117 | + |
|
118 | + 'business_details' => array( |
|
119 | + 'name' => __( "Business Details", 'invoicing' ), |
|
120 | + 'view' => array( $this, 'setup_business' ), |
|
121 | + 'handler' => '', |
|
122 | + ), |
|
123 | + |
|
124 | + 'currency' => array( |
|
125 | + 'name' => __( 'Currency', 'invoicing' ), |
|
126 | + 'view' => array( $this, 'setup_currency' ), |
|
127 | + 'handler' => '', |
|
128 | + ), |
|
129 | + |
|
130 | + 'payments' => array( |
|
131 | + 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
132 | + 'view' => array( $this, 'setup_payments' ), |
|
133 | + 'handler' => array( $this, 'setup_payments_save' ), |
|
134 | + ), |
|
135 | + |
|
136 | + 'recommend' => array( |
|
137 | + 'name' => __( 'Recommend', 'invoicing' ), |
|
138 | + 'view' => array( $this, 'setup_recommend' ), |
|
139 | + 'handler' => '', |
|
140 | + ), |
|
141 | + |
|
142 | + 'next_steps' => array( |
|
143 | + 'name' => __( 'Get Paid', 'invoicing' ), |
|
144 | + 'view' => array( $this, 'setup_ready' ), |
|
145 | + 'handler' => '', |
|
146 | + ), |
|
147 | + |
|
148 | + ); |
|
149 | + |
|
150 | + return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
151 | + |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Returns the current step. |
|
156 | + * |
|
157 | + * @since 2.4.0 |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + protected function get_current_step() { |
|
161 | + $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
162 | + return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Returns the previous step. |
|
167 | + * |
|
168 | + * @since 2.4.0 |
|
169 | + * @return string|false |
|
170 | + */ |
|
171 | + protected function get_previous_step() { |
|
172 | + |
|
173 | + $previous = false; |
|
174 | + $current = $this->step; |
|
175 | + foreach ( array_keys( $this->steps ) as $step ) { |
|
176 | + if ( $current === $step ) { |
|
177 | + return $previous; |
|
178 | + } |
|
179 | + |
|
180 | + $previous = $step; |
|
181 | + } |
|
182 | + |
|
183 | + return false; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Returns the next step. |
|
188 | + * |
|
189 | + * @since 2.4.0 |
|
190 | + * @return string|false |
|
191 | + */ |
|
192 | + protected function get_next_step() { |
|
193 | + |
|
194 | + $on_current = false; |
|
195 | + $current = $this->step; |
|
196 | + foreach ( array_keys( $this->steps ) as $step ) { |
|
197 | + |
|
198 | + if ( $on_current ) { |
|
199 | + return $step; |
|
200 | + } |
|
201 | + |
|
202 | + if ( $current === $step ) { |
|
203 | + return $on_current = true; |
|
204 | + } |
|
205 | + |
|
206 | + } |
|
207 | + |
|
208 | + return false; |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Displays the setup wizard. |
|
213 | + * |
|
214 | + * @since 2.4.0 |
|
215 | + */ |
|
216 | + public function display_wizard() { |
|
217 | + $this->display_header(); |
|
218 | + $this->display_current_step(); |
|
219 | + $this->display_footer(); |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Displays the Wizard Header. |
|
224 | + * |
|
225 | + * @since 2.0.0 |
|
226 | + */ |
|
227 | + public function display_header() { |
|
228 | + $steps = $this->steps; |
|
229 | + $current = $this->step; |
|
230 | + $next_step = $this->next_step; |
|
231 | + array_shift( $steps ); |
|
232 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Displays the content for the current step. |
|
237 | + * |
|
238 | + * @since 2.4.0 |
|
239 | + */ |
|
240 | + public function display_current_step() { |
|
241 | + ?> |
|
242 | 242 | <div class="gp-setup-content rowx mw-100 text-center mb-3"> |
243 | 243 | <div class="col-12 col-md-5 m-auto"> |
244 | 244 | <?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?> |
245 | 245 | </div> |
246 | 246 | </div> |
247 | 247 | <?php |
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Setup Wizard Footer. |
|
252 | - * |
|
253 | - * @since 2.4.0 |
|
254 | - */ |
|
255 | - public function display_footer() { |
|
256 | - |
|
257 | - if ( isset( $_GET['step'] ) ) { |
|
258 | - $next_url = esc_url( $this->get_next_step_link() ); |
|
259 | - $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
260 | - |
|
261 | - echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>'; |
|
262 | - } |
|
263 | - |
|
264 | - echo '</body></html>'; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * Introduction step. |
|
269 | - * |
|
270 | - * @since 2.0.0 |
|
271 | - */ |
|
272 | - public function setup_introduction() { |
|
273 | - $next_url = $this->get_next_step_link(); |
|
274 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Get the URL for the next step's screen. |
|
279 | - * |
|
280 | - * @param string step slug (default: current step) |
|
281 | - * |
|
282 | - * @return string URL for next step if a next step exists. |
|
283 | - * Admin URL if it's the last step. |
|
284 | - * Empty string on failure. |
|
285 | - * @since 3.0.0 |
|
286 | - */ |
|
287 | - public function get_next_step_link( $step = '' ) { |
|
288 | - if ( ! $step ) { |
|
289 | - $step = $this->step; |
|
290 | - } |
|
291 | - |
|
292 | - $keys = array_keys( $this->steps ); |
|
293 | - if ( end( $keys ) === $step ) { |
|
294 | - return admin_url(); |
|
295 | - } |
|
296 | - |
|
297 | - $step_index = array_search( $step, $keys ); |
|
298 | - if ( false === $step_index ) { |
|
299 | - return ''; |
|
300 | - } |
|
301 | - |
|
302 | - return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] )); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Setup maps api. |
|
307 | - * |
|
308 | - * @since 2.0.0 |
|
309 | - */ |
|
310 | - public function setup_business() { |
|
311 | - $next_url = $this->get_next_step_link(); |
|
312 | - $wizard = $this; |
|
313 | - $page = 'wpinv_settings_general_main'; |
|
314 | - $section = 'wpinv_settings_general_main'; |
|
315 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Default Location settings. |
|
320 | - * |
|
321 | - * @since 2.0.0 |
|
322 | - */ |
|
323 | - public function setup_currency() { |
|
324 | - $next_url = $this->get_next_step_link(); |
|
325 | - $wizard = $this; |
|
326 | - $page = 'wpinv_settings_general_currency_section'; |
|
327 | - $section = 'wpinv_settings_general_currency_section'; |
|
328 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * Installation of recommended plugins. |
|
333 | - * |
|
334 | - * @since 1.0.0 |
|
335 | - */ |
|
336 | - public function setup_recommend() { |
|
337 | - $next_url = $this->get_next_step_link(); |
|
338 | - $recommended_plugins = self::get_recommend_wp_plugins(); |
|
339 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * A list of recommended wp.org plugins. |
|
344 | - * @return array |
|
345 | - */ |
|
346 | - public static function get_recommend_wp_plugins(){ |
|
347 | - return array( |
|
348 | - 'ayecode-connect' => array( |
|
349 | - 'file' => 'ayecode-connect/ayecode-connect.php', |
|
350 | - 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
|
351 | - 'slug' => 'ayecode-connect', |
|
352 | - 'name' => 'AyeCode Connect', |
|
353 | - 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ), |
|
354 | - ), |
|
355 | - 'invoicing-quotes' => array( |
|
356 | - 'file' => 'invoicing-quotes/wpinv-quote.php', |
|
357 | - 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
|
358 | - 'slug' => 'invoicing-quotes', |
|
359 | - 'name' => 'Customer Quotes', |
|
360 | - 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'), |
|
361 | - ), |
|
362 | - 'userswp' => array( |
|
363 | - 'file' => 'userswp/userswp.php', |
|
364 | - 'url' => 'https://wordpress.org/plugins/userswp/', |
|
365 | - 'slug' => 'userswp', |
|
366 | - 'name' => 'UsersWP', |
|
367 | - 'desc' => __('Frontend user login and registration as well as slick profile pages.','geodirectory'), |
|
368 | - ), |
|
369 | - ); |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Dummy Data setup. |
|
374 | - * |
|
375 | - * @since 2.4.0 |
|
376 | - */ |
|
377 | - public function setup_payments() { |
|
378 | - $next_url = $this->get_next_step_link(); |
|
379 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Dummy data save. |
|
384 | - * |
|
385 | - * This is done via ajax so we just pass onto the next step. |
|
386 | - * |
|
387 | - * @since 2.0.0 |
|
388 | - */ |
|
389 | - public function setup_payments_save() { |
|
390 | - check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
391 | - wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
392 | - |
|
393 | - if ( ! empty( $_POST['paypal-email'] ) ) { |
|
394 | - wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
395 | - wpinv_update_option( 'paypal_active', 1 ); |
|
396 | - wpinv_update_option( 'paypal_sandbox', 0 ); |
|
397 | - } |
|
398 | - |
|
399 | - wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
400 | - exit; |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * Final step. |
|
405 | - * |
|
406 | - * @since 2.0.0 |
|
407 | - */ |
|
408 | - public function setup_ready() { |
|
409 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
410 | - } |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Setup Wizard Footer. |
|
252 | + * |
|
253 | + * @since 2.4.0 |
|
254 | + */ |
|
255 | + public function display_footer() { |
|
256 | + |
|
257 | + if ( isset( $_GET['step'] ) ) { |
|
258 | + $next_url = esc_url( $this->get_next_step_link() ); |
|
259 | + $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
260 | + |
|
261 | + echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>'; |
|
262 | + } |
|
263 | + |
|
264 | + echo '</body></html>'; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * Introduction step. |
|
269 | + * |
|
270 | + * @since 2.0.0 |
|
271 | + */ |
|
272 | + public function setup_introduction() { |
|
273 | + $next_url = $this->get_next_step_link(); |
|
274 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Get the URL for the next step's screen. |
|
279 | + * |
|
280 | + * @param string step slug (default: current step) |
|
281 | + * |
|
282 | + * @return string URL for next step if a next step exists. |
|
283 | + * Admin URL if it's the last step. |
|
284 | + * Empty string on failure. |
|
285 | + * @since 3.0.0 |
|
286 | + */ |
|
287 | + public function get_next_step_link( $step = '' ) { |
|
288 | + if ( ! $step ) { |
|
289 | + $step = $this->step; |
|
290 | + } |
|
291 | + |
|
292 | + $keys = array_keys( $this->steps ); |
|
293 | + if ( end( $keys ) === $step ) { |
|
294 | + return admin_url(); |
|
295 | + } |
|
296 | + |
|
297 | + $step_index = array_search( $step, $keys ); |
|
298 | + if ( false === $step_index ) { |
|
299 | + return ''; |
|
300 | + } |
|
301 | + |
|
302 | + return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] )); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Setup maps api. |
|
307 | + * |
|
308 | + * @since 2.0.0 |
|
309 | + */ |
|
310 | + public function setup_business() { |
|
311 | + $next_url = $this->get_next_step_link(); |
|
312 | + $wizard = $this; |
|
313 | + $page = 'wpinv_settings_general_main'; |
|
314 | + $section = 'wpinv_settings_general_main'; |
|
315 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * Default Location settings. |
|
320 | + * |
|
321 | + * @since 2.0.0 |
|
322 | + */ |
|
323 | + public function setup_currency() { |
|
324 | + $next_url = $this->get_next_step_link(); |
|
325 | + $wizard = $this; |
|
326 | + $page = 'wpinv_settings_general_currency_section'; |
|
327 | + $section = 'wpinv_settings_general_currency_section'; |
|
328 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * Installation of recommended plugins. |
|
333 | + * |
|
334 | + * @since 1.0.0 |
|
335 | + */ |
|
336 | + public function setup_recommend() { |
|
337 | + $next_url = $this->get_next_step_link(); |
|
338 | + $recommended_plugins = self::get_recommend_wp_plugins(); |
|
339 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * A list of recommended wp.org plugins. |
|
344 | + * @return array |
|
345 | + */ |
|
346 | + public static function get_recommend_wp_plugins(){ |
|
347 | + return array( |
|
348 | + 'ayecode-connect' => array( |
|
349 | + 'file' => 'ayecode-connect/ayecode-connect.php', |
|
350 | + 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
|
351 | + 'slug' => 'ayecode-connect', |
|
352 | + 'name' => 'AyeCode Connect', |
|
353 | + 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ), |
|
354 | + ), |
|
355 | + 'invoicing-quotes' => array( |
|
356 | + 'file' => 'invoicing-quotes/wpinv-quote.php', |
|
357 | + 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
|
358 | + 'slug' => 'invoicing-quotes', |
|
359 | + 'name' => 'Customer Quotes', |
|
360 | + 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'), |
|
361 | + ), |
|
362 | + 'userswp' => array( |
|
363 | + 'file' => 'userswp/userswp.php', |
|
364 | + 'url' => 'https://wordpress.org/plugins/userswp/', |
|
365 | + 'slug' => 'userswp', |
|
366 | + 'name' => 'UsersWP', |
|
367 | + 'desc' => __('Frontend user login and registration as well as slick profile pages.','geodirectory'), |
|
368 | + ), |
|
369 | + ); |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Dummy Data setup. |
|
374 | + * |
|
375 | + * @since 2.4.0 |
|
376 | + */ |
|
377 | + public function setup_payments() { |
|
378 | + $next_url = $this->get_next_step_link(); |
|
379 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Dummy data save. |
|
384 | + * |
|
385 | + * This is done via ajax so we just pass onto the next step. |
|
386 | + * |
|
387 | + * @since 2.0.0 |
|
388 | + */ |
|
389 | + public function setup_payments_save() { |
|
390 | + check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
391 | + wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
392 | + |
|
393 | + if ( ! empty( $_POST['paypal-email'] ) ) { |
|
394 | + wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
395 | + wpinv_update_option( 'paypal_active', 1 ); |
|
396 | + wpinv_update_option( 'paypal_sandbox', 0 ); |
|
397 | + } |
|
398 | + |
|
399 | + wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
400 | + exit; |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * Final step. |
|
405 | + * |
|
406 | + * @since 2.0.0 |
|
407 | + */ |
|
408 | + public function setup_ready() { |
|
409 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
410 | + } |
|
411 | 411 | |
412 | 412 | } |
413 | 413 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @version 2.4.0 |
11 | 11 | * @info GetPaid Setup Wizard. |
12 | 12 | */ |
13 | -defined( 'ABSPATH' ) || exit; |
|
13 | +defined('ABSPATH') || exit; |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * GetPaid_Admin_Setup_Wizard class. |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function __construct() { |
46 | 46 | |
47 | - if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | - add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | - add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
47 | + if (apply_filters('getpaid_enable_setup_wizard', true) && wpinv_current_user_can_manage_invoicing()) { |
|
48 | + add_action('admin_menu', array($this, 'add_menu')); |
|
49 | + add_action('current_screen', array($this, 'setup_wizard')); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @since 2.4.0 |
58 | 58 | */ |
59 | 59 | public function add_menu() { |
60 | - add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
60 | + add_dashboard_page('', '', wpinv_get_capability(), 'gp-setup', ''); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function setup_wizard() { |
69 | 69 | |
70 | - if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
70 | + if (isset($_GET['page']) && 'gp-setup' === $_GET['page']) { |
|
71 | 71 | $this->setup_globals(); |
72 | 72 | $this->maybe_save_current_step(); |
73 | 73 | $this->display_wizard(); |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | * @since 2.4.0 |
95 | 95 | */ |
96 | 96 | protected function maybe_save_current_step() { |
97 | - if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
98 | - call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
97 | + if (!empty($_POST['save_step']) && is_callable($this->steps[$this->step]['handler'])) { |
|
98 | + call_user_func($this->steps[$this->step]['handler'], $this); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
@@ -110,44 +110,44 @@ discard block |
||
110 | 110 | $steps = array( |
111 | 111 | |
112 | 112 | 'introduction' => array( |
113 | - 'name' => __( 'Introduction', 'invoicing' ), |
|
114 | - 'view' => array( $this, 'setup_introduction' ), |
|
113 | + 'name' => __('Introduction', 'invoicing'), |
|
114 | + 'view' => array($this, 'setup_introduction'), |
|
115 | 115 | 'handler' => '', |
116 | 116 | ), |
117 | 117 | |
118 | 118 | 'business_details' => array( |
119 | - 'name' => __( "Business Details", 'invoicing' ), |
|
120 | - 'view' => array( $this, 'setup_business' ), |
|
119 | + 'name' => __("Business Details", 'invoicing'), |
|
120 | + 'view' => array($this, 'setup_business'), |
|
121 | 121 | 'handler' => '', |
122 | 122 | ), |
123 | 123 | |
124 | 124 | 'currency' => array( |
125 | - 'name' => __( 'Currency', 'invoicing' ), |
|
126 | - 'view' => array( $this, 'setup_currency' ), |
|
125 | + 'name' => __('Currency', 'invoicing'), |
|
126 | + 'view' => array($this, 'setup_currency'), |
|
127 | 127 | 'handler' => '', |
128 | 128 | ), |
129 | 129 | |
130 | 130 | 'payments' => array( |
131 | - 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
132 | - 'view' => array( $this, 'setup_payments' ), |
|
133 | - 'handler' => array( $this, 'setup_payments_save' ), |
|
131 | + 'name' => __('Payment Gateways', 'invoicing'), |
|
132 | + 'view' => array($this, 'setup_payments'), |
|
133 | + 'handler' => array($this, 'setup_payments_save'), |
|
134 | 134 | ), |
135 | 135 | |
136 | 136 | 'recommend' => array( |
137 | - 'name' => __( 'Recommend', 'invoicing' ), |
|
138 | - 'view' => array( $this, 'setup_recommend' ), |
|
137 | + 'name' => __('Recommend', 'invoicing'), |
|
138 | + 'view' => array($this, 'setup_recommend'), |
|
139 | 139 | 'handler' => '', |
140 | 140 | ), |
141 | 141 | |
142 | 142 | 'next_steps' => array( |
143 | - 'name' => __( 'Get Paid', 'invoicing' ), |
|
144 | - 'view' => array( $this, 'setup_ready' ), |
|
143 | + 'name' => __('Get Paid', 'invoicing'), |
|
144 | + 'view' => array($this, 'setup_ready'), |
|
145 | 145 | 'handler' => '', |
146 | 146 | ), |
147 | 147 | |
148 | 148 | ); |
149 | 149 | |
150 | - return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
150 | + return apply_filters('getpaid_setup_wizard_steps', $steps); |
|
151 | 151 | |
152 | 152 | } |
153 | 153 | |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | protected function get_current_step() { |
161 | - $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
162 | - return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
161 | + $step = isset($_GET['step']) ? sanitize_key($_GET['step']) : ''; |
|
162 | + return !empty($step) && in_array($step, array_keys($this->steps)) ? $step : current(array_keys($this->steps)); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | |
173 | 173 | $previous = false; |
174 | 174 | $current = $this->step; |
175 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
176 | - if ( $current === $step ) { |
|
175 | + foreach (array_keys($this->steps) as $step) { |
|
176 | + if ($current === $step) { |
|
177 | 177 | return $previous; |
178 | 178 | } |
179 | 179 | |
@@ -193,13 +193,13 @@ discard block |
||
193 | 193 | |
194 | 194 | $on_current = false; |
195 | 195 | $current = $this->step; |
196 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
196 | + foreach (array_keys($this->steps) as $step) { |
|
197 | 197 | |
198 | - if ( $on_current ) { |
|
198 | + if ($on_current) { |
|
199 | 199 | return $step; |
200 | 200 | } |
201 | 201 | |
202 | - if ( $current === $step ) { |
|
202 | + if ($current === $step) { |
|
203 | 203 | return $on_current = true; |
204 | 204 | } |
205 | 205 | |
@@ -228,8 +228,8 @@ discard block |
||
228 | 228 | $steps = $this->steps; |
229 | 229 | $current = $this->step; |
230 | 230 | $next_step = $this->next_step; |
231 | - array_shift( $steps ); |
|
232 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
231 | + array_shift($steps); |
|
232 | + include plugin_dir_path(__FILE__) . 'views/wizard-header.php'; |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | ?> |
242 | 242 | <div class="gp-setup-content rowx mw-100 text-center mb-3"> |
243 | 243 | <div class="col-12 col-md-5 m-auto"> |
244 | - <?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?> |
|
244 | + <?php call_user_func($this->steps[$this->step]['view'], $this); ?> |
|
245 | 245 | </div> |
246 | 246 | </div> |
247 | 247 | <?php |
@@ -254,9 +254,9 @@ discard block |
||
254 | 254 | */ |
255 | 255 | public function display_footer() { |
256 | 256 | |
257 | - if ( isset( $_GET['step'] ) ) { |
|
258 | - $next_url = esc_url( $this->get_next_step_link() ); |
|
259 | - $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
257 | + if (isset($_GET['step'])) { |
|
258 | + $next_url = esc_url($this->get_next_step_link()); |
|
259 | + $label = $this->step == 'next_steps' ? __('Return to the WordPress Dashboard', 'invoicing') : __('Skip this step', 'invoicing'); |
|
260 | 260 | |
261 | 261 | echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>'; |
262 | 262 | } |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | */ |
272 | 272 | public function setup_introduction() { |
273 | 273 | $next_url = $this->get_next_step_link(); |
274 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
274 | + include plugin_dir_path(__FILE__) . 'views/wizard-introduction.php'; |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -284,22 +284,22 @@ discard block |
||
284 | 284 | * Empty string on failure. |
285 | 285 | * @since 3.0.0 |
286 | 286 | */ |
287 | - public function get_next_step_link( $step = '' ) { |
|
288 | - if ( ! $step ) { |
|
287 | + public function get_next_step_link($step = '') { |
|
288 | + if (!$step) { |
|
289 | 289 | $step = $this->step; |
290 | 290 | } |
291 | 291 | |
292 | - $keys = array_keys( $this->steps ); |
|
293 | - if ( end( $keys ) === $step ) { |
|
292 | + $keys = array_keys($this->steps); |
|
293 | + if (end($keys) === $step) { |
|
294 | 294 | return admin_url(); |
295 | 295 | } |
296 | 296 | |
297 | - $step_index = array_search( $step, $keys ); |
|
298 | - if ( false === $step_index ) { |
|
297 | + $step_index = array_search($step, $keys); |
|
298 | + if (false === $step_index) { |
|
299 | 299 | return ''; |
300 | 300 | } |
301 | 301 | |
302 | - return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] )); |
|
302 | + return remove_query_arg('settings-updated', add_query_arg('step', $keys[$step_index + 1])); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | $wizard = $this; |
313 | 313 | $page = 'wpinv_settings_general_main'; |
314 | 314 | $section = 'wpinv_settings_general_main'; |
315 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
315 | + include plugin_dir_path(__FILE__) . 'views/wizard-settings.php'; |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | $wizard = $this; |
326 | 326 | $page = 'wpinv_settings_general_currency_section'; |
327 | 327 | $section = 'wpinv_settings_general_currency_section'; |
328 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
328 | + include plugin_dir_path(__FILE__) . 'views/wizard-settings.php'; |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | /** |
@@ -336,35 +336,35 @@ discard block |
||
336 | 336 | public function setup_recommend() { |
337 | 337 | $next_url = $this->get_next_step_link(); |
338 | 338 | $recommended_plugins = self::get_recommend_wp_plugins(); |
339 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
339 | + include plugin_dir_path(__FILE__) . 'views/wizard-plugins.php'; |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | /** |
343 | 343 | * A list of recommended wp.org plugins. |
344 | 344 | * @return array |
345 | 345 | */ |
346 | - public static function get_recommend_wp_plugins(){ |
|
346 | + public static function get_recommend_wp_plugins() { |
|
347 | 347 | return array( |
348 | 348 | 'ayecode-connect' => array( |
349 | 349 | 'file' => 'ayecode-connect/ayecode-connect.php', |
350 | 350 | 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
351 | 351 | 'slug' => 'ayecode-connect', |
352 | 352 | 'name' => 'AyeCode Connect', |
353 | - 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ), |
|
353 | + 'desc' => __('Documentation and Support from within your WordPress admin.', 'geodirectory'), |
|
354 | 354 | ), |
355 | 355 | 'invoicing-quotes' => array( |
356 | 356 | 'file' => 'invoicing-quotes/wpinv-quote.php', |
357 | 357 | 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
358 | 358 | 'slug' => 'invoicing-quotes', |
359 | 359 | 'name' => 'Customer Quotes', |
360 | - 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'), |
|
360 | + 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.', 'geodirectory'), |
|
361 | 361 | ), |
362 | 362 | 'userswp' => array( |
363 | 363 | 'file' => 'userswp/userswp.php', |
364 | 364 | 'url' => 'https://wordpress.org/plugins/userswp/', |
365 | 365 | 'slug' => 'userswp', |
366 | 366 | 'name' => 'UsersWP', |
367 | - 'desc' => __('Frontend user login and registration as well as slick profile pages.','geodirectory'), |
|
367 | + 'desc' => __('Frontend user login and registration as well as slick profile pages.', 'geodirectory'), |
|
368 | 368 | ), |
369 | 369 | ); |
370 | 370 | } |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | */ |
377 | 377 | public function setup_payments() { |
378 | 378 | $next_url = $this->get_next_step_link(); |
379 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
379 | + include plugin_dir_path(__FILE__) . 'views/wizard-gateways.php'; |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | /** |
@@ -387,16 +387,16 @@ discard block |
||
387 | 387 | * @since 2.0.0 |
388 | 388 | */ |
389 | 389 | public function setup_payments_save() { |
390 | - check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
391 | - wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
390 | + check_admin_referer('getpaid-setup-wizard', 'getpaid-setup-wizard'); |
|
391 | + wpinv_update_option('manual_active', !empty($_POST['enable-manual-gateway'])); |
|
392 | 392 | |
393 | - if ( ! empty( $_POST['paypal-email'] ) ) { |
|
394 | - wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
395 | - wpinv_update_option( 'paypal_active', 1 ); |
|
396 | - wpinv_update_option( 'paypal_sandbox', 0 ); |
|
393 | + if (!empty($_POST['paypal-email'])) { |
|
394 | + wpinv_update_option('paypal_email', sanitize_email($_POST['paypal-email'])); |
|
395 | + wpinv_update_option('paypal_active', 1); |
|
396 | + wpinv_update_option('paypal_sandbox', 0); |
|
397 | 397 | } |
398 | 398 | |
399 | - wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
399 | + wp_redirect(esc_url_raw($this->get_next_step_link())); |
|
400 | 400 | exit; |
401 | 401 | } |
402 | 402 | |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | * @since 2.0.0 |
407 | 407 | */ |
408 | 408 | public function setup_ready() { |
409 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
409 | + include plugin_dir_path(__FILE__) . 'views/wizard-thank-you.php'; |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | ?> |
10 | 10 | |
@@ -12,54 +12,54 @@ discard block |
||
12 | 12 | |
13 | 13 | <form method="post" class="text-center card-body"> |
14 | 14 | <div class="gp-wizard-payments"> |
15 | - <h2 class="gd-settings-title h3 "><?php _e( 'Gateway Setup', 'invoicing' ); ?></h2> |
|
16 | - <p><?php _e( 'Below are a few gateways that can be setup in a few seconds.', 'invoicing' ); ?> |
|
15 | + <h2 class="gd-settings-title h3 "><?php _e('Gateway Setup', 'invoicing'); ?></h2> |
|
16 | + <p><?php _e('Below are a few gateways that can be setup in a few seconds.', 'invoicing'); ?> |
|
17 | 17 | <br> |
18 | - <?php _e( 'We have 20+ Gateways that can be setup later.', 'invoicing' ); ?> |
|
18 | + <?php _e('We have 20+ Gateways that can be setup later.', 'invoicing'); ?> |
|
19 | 19 | </p> |
20 | 20 | |
21 | 21 | <ul class="list-group"> |
22 | 22 | |
23 | 23 | <li class="list-group-item d-flex justify-content-between align-items-center"> |
24 | - <span class="mr-auto"><img src="<?php echo esc_url( WPINV_PLUGIN_URL . 'assets/images/stripe-verified.svg' );?>" class="ml-n2" alt="Stripe"></span> |
|
25 | - <?php if ( false === wpinv_get_option( 'stripe_live_connect_account_id' ) ) : ?> |
|
24 | + <span class="mr-auto"><img src="<?php echo esc_url(WPINV_PLUGIN_URL . 'assets/images/stripe-verified.svg'); ?>" class="ml-n2" alt="Stripe"></span> |
|
25 | + <?php if (false === wpinv_get_option('stripe_live_connect_account_id')) : ?> |
|
26 | 26 | <a href="<?php echo wp_nonce_url( |
27 | 27 | add_query_arg( |
28 | 28 | array( |
29 | 29 | 'getpaid-admin-action' => 'connect_gateway', |
30 | 30 | 'plugin' => 'stripe', |
31 | - 'redirect' => urlencode( add_query_arg( 'step', 'payments' ) ), |
|
31 | + 'redirect' => urlencode(add_query_arg('step', 'payments')), |
|
32 | 32 | ), |
33 | 33 | admin_url() |
34 | 34 | ), |
35 | 35 | 'getpaid-nonce', |
36 | 36 | 'getpaid-nonce' |
37 | 37 | ); ?>" |
38 | - class="btn btn-sm btn-outline-primary"><?php _e( 'Connect', 'invoicing' ); ?></a> |
|
38 | + class="btn btn-sm btn-outline-primary"><?php _e('Connect', 'invoicing'); ?></a> |
|
39 | 39 | <?php else: ?> |
40 | - <span class="btn btn-sm btn-success"><?php _e( 'Connected', 'invoicing' ); ?></span> |
|
40 | + <span class="btn btn-sm btn-success"><?php _e('Connected', 'invoicing'); ?></span> |
|
41 | 41 | <?php endif; ?> |
42 | 42 | </li> |
43 | 43 | |
44 | 44 | <li class="list-group-item"> |
45 | 45 | <div class="d-flex justify-content-between align-items-center"> |
46 | 46 | <span class="mr-auto"> |
47 | - <img src="<?php echo esc_url( WPINV_PLUGIN_URL . 'assets/images/pp-logo-150px.webp' );?>" class="" alt="PayPal" height="25"> |
|
47 | + <img src="<?php echo esc_url(WPINV_PLUGIN_URL . 'assets/images/pp-logo-150px.webp'); ?>" class="" alt="PayPal" height="25"> |
|
48 | 48 | </span> |
49 | 49 | <a |
50 | 50 | href="#" |
51 | 51 | onclick="jQuery('.getpaid-setup-paypal-input').toggleClass('d-none'); return false;" |
52 | - class="getpaid-setup-paypal btn btn-sm btn-outline-primary"><?php _e( 'Set-up', 'invoicing' ); ?></a> |
|
52 | + class="getpaid-setup-paypal btn btn-sm btn-outline-primary"><?php _e('Set-up', 'invoicing'); ?></a> |
|
53 | 53 | </div> |
54 | 54 | <div class="mt-4 getpaid-setup-paypal-input d-none"> |
55 | - <input type="text" placeholder="<?php esc_attr_e( 'PayPal Email', 'invoicing' ); ?>" name="paypal-email" class="form-control" value="<?php echo esc_attr( wpinv_get_option( 'paypal_email' ) ); ?>"> |
|
55 | + <input type="text" placeholder="<?php esc_attr_e('PayPal Email', 'invoicing'); ?>" name="paypal-email" class="form-control" value="<?php echo esc_attr(wpinv_get_option('paypal_email')); ?>"> |
|
56 | 56 | </div> |
57 | 57 | </li> |
58 | 58 | |
59 | 59 | <li class="list-group-item d-flex justify-content-between align-items-center"> |
60 | - <span class="mr-auto"><?php _e( 'Test Getway', 'invoicing' ); ?></span> |
|
60 | + <span class="mr-auto"><?php _e('Test Getway', 'invoicing'); ?></span> |
|
61 | 61 | <div class="custom-control custom-switch"> |
62 | - <input type="checkbox" name="enable-manual-gateway" class="custom-control-input" id="enable-manual-gateway" <?php checked( wpinv_is_gateway_active( 'manual' ) ); ?>> |
|
62 | + <input type="checkbox" name="enable-manual-gateway" class="custom-control-input" id="enable-manual-gateway" <?php checked(wpinv_is_gateway_active('manual')); ?>> |
|
63 | 63 | <label class="custom-control-label" for="enable-manual-gateway"></label> |
64 | 64 | </div> |
65 | 65 | </li> |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | </div> |
69 | 69 | |
70 | 70 | <p class="gp-setup-actions step text-center mt-4"> |
71 | - <input type="submit" class="btn btn-primary" value="<?php esc_attr_e( 'Continue', 'invoicing' ); ?>" /> |
|
71 | + <input type="submit" class="btn btn-primary" value="<?php esc_attr_e('Continue', 'invoicing'); ?>" /> |
|
72 | 72 | </p> |
73 | 73 | |
74 | - <?php getpaid_hidden_field( 'save_step', 1 ); ?> |
|
75 | - <?php wp_nonce_field( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); ?> |
|
74 | + <?php getpaid_hidden_field('save_step', 1); ?> |
|
75 | + <?php wp_nonce_field('getpaid-setup-wizard', 'getpaid-setup-wizard'); ?> |
|
76 | 76 | </form> |
77 | 77 | </div> |
@@ -36,8 +36,11 @@ |
||
36 | 36 | 'getpaid-nonce' |
37 | 37 | ); ?>" |
38 | 38 | class="btn btn-sm btn-outline-primary"><?php _e( 'Connect', 'invoicing' ); ?></a> |
39 | - <?php else: ?> |
|
40 | - <span class="btn btn-sm btn-success"><?php _e( 'Connected', 'invoicing' ); ?></span> |
|
39 | + <?php else { |
|
40 | + : ?> |
|
41 | + <span class="btn btn-sm btn-success"><?php _e( 'Connected', 'invoicing' ); |
|
42 | +} |
|
43 | +?></span> |
|
41 | 44 | <?php endif; ?> |
42 | 45 | </li> |
43 | 46 |
@@ -4,78 +4,78 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | ?> |
10 | 10 | |
11 | 11 | <div class="card shadow-sm my-5"> |
12 | 12 | |
13 | 13 | <h1 class="h4 card-header bg-white border-bottom-0 pt-4 pb-1"> |
14 | - <?php esc_html_e( 'Welcome to the GetPaid Setup Wizard!', 'invoicing' ); ?> |
|
14 | + <?php esc_html_e('Welcome to the GetPaid Setup Wizard!', 'invoicing'); ?> |
|
15 | 15 | </h1> |
16 | 16 | |
17 | 17 | <div class="card-body text-muted "> |
18 | - <p><?php _e( 'Thank you for choosing GetPaid - The most Powerful Payments Plugin for WordPress', 'invoicing' ); ?></p> |
|
18 | + <p><?php _e('Thank you for choosing GetPaid - The most Powerful Payments Plugin for WordPress', 'invoicing'); ?></p> |
|
19 | 19 | <hr class="mt-4 pt-3 pb-0" /> |
20 | - <p class="small"><?php _e( 'This quick setup wizard will help you <b>configure the basic settings</b>. It’s <b>completely optional</b> and shouldn’t take longer than <b>five minutes</b>.', 'invoicing' ); ?></p> |
|
20 | + <p class="small"><?php _e('This quick setup wizard will help you <b>configure the basic settings</b>. It’s <b>completely optional</b> and shouldn’t take longer than <b>five minutes</b>.', 'invoicing'); ?></p> |
|
21 | 21 | </div> |
22 | 22 | |
23 | 23 | <div class="card-footer mb-0 bg-white gp-setup-actions step border-top-0"> |
24 | 24 | <a |
25 | - href="<?php echo esc_url( $next_url ); ?>" |
|
26 | - class="btn btn-primary button-next"><?php esc_html_e( "Let's go!", 'invoicing' ); ?></a> |
|
25 | + href="<?php echo esc_url($next_url); ?>" |
|
26 | + class="btn btn-primary button-next"><?php esc_html_e("Let's go!", 'invoicing'); ?></a> |
|
27 | 27 | <a |
28 | - href="<?php echo esc_url( admin_url() ); ?>" |
|
29 | - class="btn btn-link d-block mt-2 "><?php esc_html_e( 'Not right now', 'invoicing' ); ?></a> |
|
28 | + href="<?php echo esc_url(admin_url()); ?>" |
|
29 | + class="btn btn-link d-block mt-2 "><?php esc_html_e('Not right now', 'invoicing'); ?></a> |
|
30 | 30 | </div> |
31 | 31 | </div> |
32 | 32 | |
33 | 33 | <div class="card shadow-sm my-5 overflow-hidden"> |
34 | 34 | <h1 class="h4 card-header bg-white border-bottom-0 pt-4 pb-1"> |
35 | - <?php esc_html_e( 'GetPaid Features & Addons!', 'invoicing' ); ?> |
|
35 | + <?php esc_html_e('GetPaid Features & Addons!', 'invoicing'); ?> |
|
36 | 36 | </h1> |
37 | 37 | |
38 | 38 | <div class="card-body text-muted overflow-hidden"> |
39 | - <p><?php _e( 'Collect one time & recurring payments online within minutes. No complex setup required.', 'invoicing' ); ?></p> |
|
39 | + <p><?php _e('Collect one time & recurring payments online within minutes. No complex setup required.', 'invoicing'); ?></p> |
|
40 | 40 | <hr> |
41 | 41 | |
42 | 42 | <div class="row row-cols-2 text-left"> |
43 | 43 | <div class="col mt-3"> |
44 | 44 | <div class="media"> |
45 | - <img src="<?php echo WPINV_PLUGIN_URL . 'assets/images/buy.svg';?>" class="mr-3" alt="..."> |
|
45 | + <img src="<?php echo WPINV_PLUGIN_URL . 'assets/images/buy.svg'; ?>" class="mr-3" alt="..."> |
|
46 | 46 | <div class="media-body"> |
47 | - <h6 class="mt-0 font-weight-bold"><?php _e( 'GetPaid via Buy Now Buttons', 'invoicing' );?></h6> |
|
48 | - <small><?php _e( 'Sell via buy now buttons anywhere on your site', 'invoicing' );?></small> |
|
47 | + <h6 class="mt-0 font-weight-bold"><?php _e('GetPaid via Buy Now Buttons', 'invoicing'); ?></h6> |
|
48 | + <small><?php _e('Sell via buy now buttons anywhere on your site', 'invoicing'); ?></small> |
|
49 | 49 | </div> |
50 | 50 | </div> |
51 | 51 | </div> |
52 | 52 | |
53 | 53 | <div class="col mt-3"> |
54 | 54 | <div class="media"> |
55 | - <img src="<?php echo WPINV_PLUGIN_URL . 'assets/images/report.svg';?>" class="mr-3" alt="..."> |
|
55 | + <img src="<?php echo WPINV_PLUGIN_URL . 'assets/images/report.svg'; ?>" class="mr-3" alt="..."> |
|
56 | 56 | <div class="media-body"> |
57 | - <h6 class="mt-0 font-weight-bold"><?php _e( 'GetPaid via payment form', 'invoicing' );?></h6> |
|
58 | - <small><?php _e( 'Payment forms are conversion-optimized checkout forms', 'invoicing' );?></small> |
|
57 | + <h6 class="mt-0 font-weight-bold"><?php _e('GetPaid via payment form', 'invoicing'); ?></h6> |
|
58 | + <small><?php _e('Payment forms are conversion-optimized checkout forms', 'invoicing'); ?></small> |
|
59 | 59 | </div> |
60 | 60 | </div> |
61 | 61 | </div> |
62 | 62 | |
63 | 63 | <div class="col mt-3"> |
64 | 64 | <div class="media"> |
65 | - <img src="<?php echo WPINV_PLUGIN_URL . 'assets/images/invoices.svg';?>" class="mr-3" alt="..."> |
|
65 | + <img src="<?php echo WPINV_PLUGIN_URL . 'assets/images/invoices.svg'; ?>" class="mr-3" alt="..."> |
|
66 | 66 | <div class="media-body"> |
67 | - <h6 class="mt-0 font-weight-bold"><?php _e('GetPaid via Invoice','invoicing');?></h6> |
|
68 | - <small><?php _e('Create and send invoices for just about anything from the WordPress dashboard','invoicing');?></small> |
|
67 | + <h6 class="mt-0 font-weight-bold"><?php _e('GetPaid via Invoice', 'invoicing'); ?></h6> |
|
68 | + <small><?php _e('Create and send invoices for just about anything from the WordPress dashboard', 'invoicing'); ?></small> |
|
69 | 69 | </div> |
70 | 70 | </div> |
71 | 71 | </div> |
72 | 72 | |
73 | 73 | <div class="col mt-3"> |
74 | 74 | <div class="media"> |
75 | - <img src="<?php echo WPINV_PLUGIN_URL . 'assets/images/payment.svg';?>" class="mr-3" alt="..."> |
|
75 | + <img src="<?php echo WPINV_PLUGIN_URL . 'assets/images/payment.svg'; ?>" class="mr-3" alt="..."> |
|
76 | 76 | <div class="media-body"> |
77 | - <h6 class="mt-0 font-weight-bold"><?php _e('Affordable payment gateways','invoicing');?></h6> |
|
78 | - <small><?php _e('On average our gateways are over 66% cheaper than our competition','invoicing');?></small> |
|
77 | + <h6 class="mt-0 font-weight-bold"><?php _e('Affordable payment gateways', 'invoicing'); ?></h6> |
|
78 | + <small><?php _e('On average our gateways are over 66% cheaper than our competition', 'invoicing'); ?></small> |
|
79 | 79 | </div> |
80 | 80 | </div> |
81 | 81 | </div> |
@@ -86,51 +86,51 @@ discard block |
||
86 | 86 | <div class="mt-5"> |
87 | 87 | <a |
88 | 88 | href="https://wpgetpaid.com/features-list/" |
89 | - class="btn btn-primary"><?php esc_html_e( 'View All Features!', 'invoicing' ); ?></a> |
|
89 | + class="btn btn-primary"><?php esc_html_e('View All Features!', 'invoicing'); ?></a> |
|
90 | 90 | </div> |
91 | 91 | |
92 | 92 | <div class="mt-5 mx-n4 py-4" style="background:#eafaf6;"> |
93 | - <h4 class="mt-0 font-weight-bold text-dark mb-4"><?php _e( 'More with Membership!' , 'invoicing' );?></h4> |
|
93 | + <h4 class="mt-0 font-weight-bold text-dark mb-4"><?php _e('More with Membership!', 'invoicing'); ?></h4> |
|
94 | 94 | <div class="row row-cols-2 text-left px-5"> |
95 | 95 | |
96 | 96 | <div class="col"> |
97 | 97 | <ul class="list-unstyled"> |
98 | - <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e( 'PDF Invoices' , 'invoicing' );?></li> |
|
99 | - <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e( 'Gravity Forms' , 'invoicing' );?></li> |
|
100 | - <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e( 'Contact form 7' , 'invoicing' );?></li> |
|
101 | - <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e( 'AffiliateWP Integration' , 'invoicing' );?></li> |
|
98 | + <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e('PDF Invoices', 'invoicing'); ?></li> |
|
99 | + <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e('Gravity Forms', 'invoicing'); ?></li> |
|
100 | + <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e('Contact form 7', 'invoicing'); ?></li> |
|
101 | + <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e('AffiliateWP Integration', 'invoicing'); ?></li> |
|
102 | 102 | </ul> |
103 | 103 | </div> |
104 | 104 | |
105 | 105 | <div class="col"> |
106 | 106 | <ul class="list-unstyled"> |
107 | - <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e( 'Ninja forms' , 'invoicing' );?></li> |
|
108 | - <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e( 'Digital Downloads' , 'invoicing' );?></li> |
|
109 | - <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e( 'Wallet' , 'invoicing' );?></li> |
|
107 | + <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e('Ninja forms', 'invoicing'); ?></li> |
|
108 | + <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e('Digital Downloads', 'invoicing'); ?></li> |
|
109 | + <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e('Wallet', 'invoicing'); ?></li> |
|
110 | 110 | </ul> |
111 | 111 | </div> |
112 | 112 | </div> |
113 | 113 | |
114 | - <h5 class="mt-4 font-weight-bold text-dark mb-3"><?php _e('Membership Starts From','invoicing');?></h5> |
|
115 | - <h1 class="mt-0 font-weight-bold text-dark mb-4 display-3"><?php esc_html_e( '$49', 'invoicing' ); ?></h1> |
|
114 | + <h5 class="mt-4 font-weight-bold text-dark mb-3"><?php _e('Membership Starts From', 'invoicing'); ?></h5> |
|
115 | + <h1 class="mt-0 font-weight-bold text-dark mb-4 display-3"><?php esc_html_e('$49', 'invoicing'); ?></h1> |
|
116 | 116 | |
117 | 117 | <div class="mt-2"> |
118 | 118 | <a |
119 | 119 | href="https://wpgetpaid.com/downloads/membership/" |
120 | - class="btn btn-primary"><?php esc_html_e( 'Buy Membership Now!', 'invoicing' ); ?></a> |
|
120 | + class="btn btn-primary"><?php esc_html_e('Buy Membership Now!', 'invoicing'); ?></a> |
|
121 | 121 | </div> |
122 | 122 | |
123 | 123 | </div> |
124 | 124 | |
125 | 125 | <div class="card-footer mb-0 bg-white gp-setup-actions step border-top-0"> |
126 | 126 | <a |
127 | - href="<?php echo esc_url( $next_url ); ?>" |
|
128 | - class="btn btn-outline-primary button-next"><?php esc_html_e( 'Launch the Setup Wizard!', 'invoicing' ); ?></a> |
|
127 | + href="<?php echo esc_url($next_url); ?>" |
|
128 | + class="btn btn-outline-primary button-next"><?php esc_html_e('Launch the Setup Wizard!', 'invoicing'); ?></a> |
|
129 | 129 | <a |
130 | 130 | href="https://docs.wpgetpaid.com/" |
131 | - class="btn btn-outline-primary ml-4"><?php esc_html_e( 'Documentation', 'invoicing' ); ?></a> |
|
131 | + class="btn btn-outline-primary ml-4"><?php esc_html_e('Documentation', 'invoicing'); ?></a> |
|
132 | 132 | <a |
133 | - href="<?php echo esc_url( admin_url() ); ?>" |
|
134 | - class="btn btn-link d-block mt-2 "><?php esc_html_e( 'Not right now', 'invoicing' ); ?></a> |
|
133 | + href="<?php echo esc_url(admin_url()); ?>" |
|
134 | + class="btn btn-link d-block mt-2 "><?php esc_html_e('Not right now', 'invoicing'); ?></a> |
|
135 | 135 | </div> |
136 | 136 | </div> |
@@ -12,145 +12,145 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Daily_Maintenance { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - */ |
|
18 | - public function __construct(){ |
|
19 | - |
|
20 | - // Clear deprecated events. |
|
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | - |
|
23 | - // (Maybe) schedule a cron that runs daily. |
|
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | - |
|
26 | - // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
32 | - |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Schedules a cron to run every day at 7 a.m |
|
37 | - * |
|
38 | - */ |
|
39 | - public function maybe_create_scheduled_event() { |
|
40 | - |
|
41 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
44 | - } |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Clears deprecated events. |
|
50 | - * |
|
51 | - */ |
|
52 | - public function maybe_clear_deprecated_events() { |
|
53 | - |
|
54 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
58 | - } |
|
59 | - |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Fires the old hook for backwards compatibility. |
|
64 | - * |
|
65 | - */ |
|
66 | - public function backwards_compat() { |
|
67 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Checks for subscriptions that are scheduled to renew. |
|
72 | - * |
|
73 | - */ |
|
74 | - public function check_renewing_subscriptions() { |
|
75 | - |
|
76 | - // Fetch subscriptions that expire today. |
|
77 | - $args = array( |
|
78 | - 'number' => -1, |
|
79 | - 'count_total' => false, |
|
80 | - 'status' => 'trialling active', |
|
81 | - 'date_expires_query' => array( |
|
82 | - array( |
|
83 | - 'year' => date( 'Y', current_time( 'timestamp' ) ), |
|
84 | - 'month' => date( 'n', current_time( 'timestamp' ) ), |
|
85 | - 'day' => date( 'j', current_time( 'timestamp' ) ), |
|
86 | - 'compare' => '=', |
|
87 | - ), |
|
88 | - ), |
|
89 | - ); |
|
90 | - |
|
91 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
92 | - |
|
93 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
94 | - |
|
95 | - /** @var WPInv_Subscription $subscription */ |
|
96 | - if ( $subscription->is_last_renewal() ) { |
|
97 | - $subscription->complete(); |
|
98 | - } else { |
|
99 | - do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
100 | - } |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Expires expired subscriptions. |
|
108 | - * |
|
109 | - */ |
|
110 | - public function maybe_expire_subscriptions() { |
|
111 | - |
|
112 | - // Fetch expired subscriptions (skips those that expire today). |
|
113 | - $args = array( |
|
114 | - 'number' => -1, |
|
115 | - 'count_total' => false, |
|
116 | - 'status' => 'trialling active failing cancelled', |
|
117 | - 'date_expires_query' => array( |
|
118 | - 'before' => 'yesterday', |
|
119 | - 'inclusive' => false, |
|
120 | - ), |
|
121 | - ); |
|
122 | - |
|
123 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
124 | - |
|
125 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
126 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
127 | - $subscription->set_status( 'expired' ); |
|
128 | - $subscription->save(); |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Logs cron runs. |
|
136 | - * |
|
137 | - */ |
|
138 | - public function log_cron_run() { |
|
139 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Updates GeoIP databases. |
|
144 | - * |
|
145 | - */ |
|
146 | - public function maybe_update_geoip_databases() { |
|
147 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
148 | - |
|
149 | - if ( false === $updated ) { |
|
150 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
151 | - do_action( 'getpaid_update_geoip_databases' ); |
|
152 | - } |
|
153 | - |
|
154 | - } |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + */ |
|
18 | + public function __construct(){ |
|
19 | + |
|
20 | + // Clear deprecated events. |
|
21 | + add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | + |
|
23 | + // (Maybe) schedule a cron that runs daily. |
|
24 | + add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | + |
|
26 | + // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | + add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | + add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | + add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
32 | + |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Schedules a cron to run every day at 7 a.m |
|
37 | + * |
|
38 | + */ |
|
39 | + public function maybe_create_scheduled_event() { |
|
40 | + |
|
41 | + if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | + $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | + wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
44 | + } |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Clears deprecated events. |
|
50 | + * |
|
51 | + */ |
|
52 | + public function maybe_clear_deprecated_events() { |
|
53 | + |
|
54 | + if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | + update_option( 'wpinv_cleared_old_events', 1 ); |
|
58 | + } |
|
59 | + |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Fires the old hook for backwards compatibility. |
|
64 | + * |
|
65 | + */ |
|
66 | + public function backwards_compat() { |
|
67 | + do_action( 'wpinv_register_schedule_event_daily' ); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Checks for subscriptions that are scheduled to renew. |
|
72 | + * |
|
73 | + */ |
|
74 | + public function check_renewing_subscriptions() { |
|
75 | + |
|
76 | + // Fetch subscriptions that expire today. |
|
77 | + $args = array( |
|
78 | + 'number' => -1, |
|
79 | + 'count_total' => false, |
|
80 | + 'status' => 'trialling active', |
|
81 | + 'date_expires_query' => array( |
|
82 | + array( |
|
83 | + 'year' => date( 'Y', current_time( 'timestamp' ) ), |
|
84 | + 'month' => date( 'n', current_time( 'timestamp' ) ), |
|
85 | + 'day' => date( 'j', current_time( 'timestamp' ) ), |
|
86 | + 'compare' => '=', |
|
87 | + ), |
|
88 | + ), |
|
89 | + ); |
|
90 | + |
|
91 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
92 | + |
|
93 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
94 | + |
|
95 | + /** @var WPInv_Subscription $subscription */ |
|
96 | + if ( $subscription->is_last_renewal() ) { |
|
97 | + $subscription->complete(); |
|
98 | + } else { |
|
99 | + do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
100 | + } |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Expires expired subscriptions. |
|
108 | + * |
|
109 | + */ |
|
110 | + public function maybe_expire_subscriptions() { |
|
111 | + |
|
112 | + // Fetch expired subscriptions (skips those that expire today). |
|
113 | + $args = array( |
|
114 | + 'number' => -1, |
|
115 | + 'count_total' => false, |
|
116 | + 'status' => 'trialling active failing cancelled', |
|
117 | + 'date_expires_query' => array( |
|
118 | + 'before' => 'yesterday', |
|
119 | + 'inclusive' => false, |
|
120 | + ), |
|
121 | + ); |
|
122 | + |
|
123 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
124 | + |
|
125 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
126 | + if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
127 | + $subscription->set_status( 'expired' ); |
|
128 | + $subscription->save(); |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Logs cron runs. |
|
136 | + * |
|
137 | + */ |
|
138 | + public function log_cron_run() { |
|
139 | + wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Updates GeoIP databases. |
|
144 | + * |
|
145 | + */ |
|
146 | + public function maybe_update_geoip_databases() { |
|
147 | + $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
148 | + |
|
149 | + if ( false === $updated ) { |
|
150 | + set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
151 | + do_action( 'getpaid_update_geoip_databases' ); |
|
152 | + } |
|
153 | + |
|
154 | + } |
|
155 | 155 | |
156 | 156 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Daily maintenance class. |
@@ -15,20 +15,20 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * Class constructor. |
17 | 17 | */ |
18 | - public function __construct(){ |
|
18 | + public function __construct() { |
|
19 | 19 | |
20 | 20 | // Clear deprecated events. |
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
21 | + add_action('wp', array($this, 'maybe_clear_deprecated_events')); |
|
22 | 22 | |
23 | 23 | // (Maybe) schedule a cron that runs daily. |
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
24 | + add_action('wp', array($this, 'maybe_create_scheduled_event')); |
|
25 | 25 | |
26 | 26 | // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
27 | + add_action('getpaid_daily_maintenance', array($this, 'log_cron_run')); |
|
28 | + add_action('getpaid_daily_maintenance', array($this, 'backwards_compat')); |
|
29 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_expire_subscriptions')); |
|
30 | + add_action('getpaid_daily_maintenance', array($this, 'check_renewing_subscriptions')); |
|
31 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_update_geoip_databases')); |
|
32 | 32 | |
33 | 33 | } |
34 | 34 | |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function maybe_create_scheduled_event() { |
40 | 40 | |
41 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
41 | + if (!wp_next_scheduled('getpaid_daily_maintenance')) { |
|
42 | + $timestamp = strtotime('tomorrow 07:00:00', current_time('timestamp')); |
|
43 | + wp_schedule_event($timestamp, 'daily', 'getpaid_daily_maintenance'); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | } |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function maybe_clear_deprecated_events() { |
53 | 53 | |
54 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
54 | + if (!get_option('wpinv_cleared_old_events')) { |
|
55 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily'); |
|
56 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_daily'); |
|
57 | + update_option('wpinv_cleared_old_events', 1); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * |
65 | 65 | */ |
66 | 66 | public function backwards_compat() { |
67 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
67 | + do_action('wpinv_register_schedule_event_daily'); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -74,29 +74,29 @@ discard block |
||
74 | 74 | public function check_renewing_subscriptions() { |
75 | 75 | |
76 | 76 | // Fetch subscriptions that expire today. |
77 | - $args = array( |
|
77 | + $args = array( |
|
78 | 78 | 'number' => -1, |
79 | 79 | 'count_total' => false, |
80 | 80 | 'status' => 'trialling active', |
81 | 81 | 'date_expires_query' => array( |
82 | 82 | array( |
83 | - 'year' => date( 'Y', current_time( 'timestamp' ) ), |
|
84 | - 'month' => date( 'n', current_time( 'timestamp' ) ), |
|
85 | - 'day' => date( 'j', current_time( 'timestamp' ) ), |
|
83 | + 'year' => date('Y', current_time('timestamp')), |
|
84 | + 'month' => date('n', current_time('timestamp')), |
|
85 | + 'day' => date('j', current_time('timestamp')), |
|
86 | 86 | 'compare' => '=', |
87 | 87 | ), |
88 | 88 | ), |
89 | 89 | ); |
90 | 90 | |
91 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
91 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
92 | 92 | |
93 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
93 | + foreach ($subscriptions->get_results() as $subscription) { |
|
94 | 94 | |
95 | 95 | /** @var WPInv_Subscription $subscription */ |
96 | - if ( $subscription->is_last_renewal() ) { |
|
96 | + if ($subscription->is_last_renewal()) { |
|
97 | 97 | $subscription->complete(); |
98 | 98 | } else { |
99 | - do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
99 | + do_action('getpaid_should_renew_subscription', $subscription); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | public function maybe_expire_subscriptions() { |
111 | 111 | |
112 | 112 | // Fetch expired subscriptions (skips those that expire today). |
113 | - $args = array( |
|
113 | + $args = array( |
|
114 | 114 | 'number' => -1, |
115 | 115 | 'count_total' => false, |
116 | 116 | 'status' => 'trialling active failing cancelled', |
@@ -120,11 +120,11 @@ discard block |
||
120 | 120 | ), |
121 | 121 | ); |
122 | 122 | |
123 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
123 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
124 | 124 | |
125 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
126 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
127 | - $subscription->set_status( 'expired' ); |
|
125 | + foreach ($subscriptions->get_results() as $subscription) { |
|
126 | + if (apply_filters('getpaid_daily_maintenance_should_expire_subscription', false, $subscription)) { |
|
127 | + $subscription->set_status('expired'); |
|
128 | 128 | $subscription->save(); |
129 | 129 | } |
130 | 130 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * |
137 | 137 | */ |
138 | 138 | public function log_cron_run() { |
139 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
139 | + wpinv_error_log('GetPaid Daily Cron', false); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -144,11 +144,11 @@ discard block |
||
144 | 144 | * |
145 | 145 | */ |
146 | 146 | public function maybe_update_geoip_databases() { |
147 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
147 | + $updated = get_transient('getpaid_updated_geoip_databases'); |
|
148 | 148 | |
149 | - if ( false === $updated ) { |
|
150 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
151 | - do_action( 'getpaid_update_geoip_databases' ); |
|
149 | + if (false === $updated) { |
|
150 | + set_transient('getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS); |
|
151 | + do_action('getpaid_update_geoip_databases'); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -21,300 +21,300 @@ discard block |
||
21 | 21 | */ |
22 | 22 | if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
23 | 23 | |
24 | - /** |
|
25 | - * A Class to be able to change settings for Font Awesome. |
|
26 | - * |
|
27 | - * Class WP_Font_Awesome_Settings |
|
28 | - * @since 1.0.10 Now able to pass wp.org theme check. |
|
29 | - * @since 1.0.11 Font Awesome Pro now supported. |
|
30 | - * @since 1.0.11 Font Awesome Kits now supported. |
|
31 | - * @since 1.0.13 RTL language support added. |
|
32 | - * @ver 1.0.13 |
|
33 | - * @todo decide how to implement textdomain |
|
34 | - */ |
|
35 | - class WP_Font_Awesome_Settings { |
|
36 | - |
|
37 | - /** |
|
38 | - * Class version version. |
|
39 | - * |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - public $version = '1.0.13'; |
|
43 | - |
|
44 | - /** |
|
45 | - * Class textdomain. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $textdomain = 'font-awesome-settings'; |
|
50 | - |
|
51 | - /** |
|
52 | - * Latest version of Font Awesome at time of publish published. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - public $latest = "5.8.2"; |
|
57 | - |
|
58 | - /** |
|
59 | - * The title. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $name = 'Font Awesome'; |
|
64 | - |
|
65 | - /** |
|
66 | - * Holds the settings values. |
|
67 | - * |
|
68 | - * @var array |
|
69 | - */ |
|
70 | - private $settings; |
|
71 | - |
|
72 | - /** |
|
73 | - * WP_Font_Awesome_Settings instance. |
|
74 | - * |
|
75 | - * @access private |
|
76 | - * @since 1.0.0 |
|
77 | - * @var WP_Font_Awesome_Settings There can be only one! |
|
78 | - */ |
|
79 | - private static $instance = null; |
|
80 | - |
|
81 | - /** |
|
82 | - * Main WP_Font_Awesome_Settings Instance. |
|
83 | - * |
|
84 | - * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
85 | - * |
|
86 | - * @since 1.0.0 |
|
87 | - * @static |
|
88 | - * @return WP_Font_Awesome_Settings - Main instance. |
|
89 | - */ |
|
90 | - public static function instance() { |
|
91 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
92 | - self::$instance = new WP_Font_Awesome_Settings; |
|
93 | - |
|
94 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
95 | - |
|
96 | - if ( is_admin() ) { |
|
97 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
98 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
99 | - } |
|
100 | - |
|
101 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
102 | - } |
|
103 | - |
|
104 | - return self::$instance; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Initiate the settings and add the required action hooks. |
|
109 | - * |
|
110 | - * @since 1.0.8 Settings name wrong - FIXED |
|
111 | - */ |
|
112 | - public function init() { |
|
113 | - $this->settings = $this->get_settings(); |
|
114 | - |
|
115 | - if ( $this->settings['type'] == 'CSS' ) { |
|
116 | - |
|
117 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
118 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
119 | - } |
|
120 | - |
|
121 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
122 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
123 | - } |
|
124 | - |
|
125 | - } else { |
|
126 | - |
|
127 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
128 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
129 | - } |
|
130 | - |
|
131 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
132 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - // remove font awesome if set to do so |
|
137 | - if ( $this->settings['dequeue'] == '1' ) { |
|
138 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
139 | - } |
|
140 | - |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Adds the Font Awesome styles. |
|
145 | - */ |
|
146 | - public function enqueue_style() { |
|
147 | - // build url |
|
148 | - $url = $this->get_url(); |
|
149 | - |
|
150 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
151 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
152 | - wp_enqueue_style( 'font-awesome' ); |
|
153 | - |
|
154 | - // RTL language support CSS. |
|
155 | - if ( is_rtl() ) { |
|
156 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
157 | - } |
|
158 | - |
|
159 | - if ( $this->settings['shims'] ) { |
|
160 | - $url = $this->get_url( true ); |
|
161 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
162 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
163 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Adds the Font Awesome JS. |
|
169 | - */ |
|
170 | - public function enqueue_scripts() { |
|
171 | - // build url |
|
172 | - $url = $this->get_url(); |
|
173 | - |
|
174 | - $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
175 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
176 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
177 | - wp_enqueue_script( 'font-awesome' ); |
|
178 | - |
|
179 | - if ( $this->settings['shims'] ) { |
|
180 | - $url = $this->get_url( true ); |
|
181 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
182 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
183 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Get the url of the Font Awesome files. |
|
189 | - * |
|
190 | - * @param bool $shims If this is a shim file or not. |
|
191 | - * |
|
192 | - * @return string The url to the file. |
|
193 | - */ |
|
194 | - public function get_url( $shims = false ) { |
|
195 | - $script = $shims ? 'v4-shims' : 'all'; |
|
196 | - $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
197 | - $type = $this->settings['type']; |
|
198 | - $version = $this->settings['version']; |
|
199 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
200 | - $url = ''; |
|
201 | - |
|
202 | - if ( $type == 'KIT' && $kit_url ) { |
|
203 | - if ( $shims ) { |
|
204 | - // if its a kit then we don't add shims here |
|
205 | - return ''; |
|
206 | - } |
|
207 | - $url .= $kit_url; // CDN |
|
208 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
209 | - } else { |
|
210 | - $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
211 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
212 | - $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
213 | - $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
214 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
215 | - } |
|
216 | - |
|
217 | - return $url; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
222 | - * |
|
223 | - * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
224 | - * |
|
225 | - * @param $url |
|
226 | - * @param $original_url |
|
227 | - * @param $_context |
|
228 | - * |
|
229 | - * @return string The filtered url. |
|
230 | - */ |
|
231 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
232 | - |
|
233 | - if ( $_context == 'display' |
|
234 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
235 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
236 | - ) {// it's a font-awesome-url (probably) |
|
237 | - |
|
238 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
239 | - if ( $this->settings['type'] == 'JS' ) { |
|
240 | - if ( $this->settings['js-pseudo'] ) { |
|
241 | - $url .= "' data-search-pseudo-elements defer='defer"; |
|
242 | - } else { |
|
243 | - $url .= "' defer='defer"; |
|
244 | - } |
|
245 | - } |
|
246 | - } else { |
|
247 | - $url = ''; // removing the url removes the file |
|
248 | - } |
|
249 | - |
|
250 | - } |
|
251 | - |
|
252 | - return $url; |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Register the database settings with WordPress. |
|
257 | - */ |
|
258 | - public function register_settings() { |
|
259 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Add the WordPress settings menu item. |
|
264 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
265 | - */ |
|
266 | - public function menu_item() { |
|
267 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
268 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
269 | - $this, |
|
270 | - 'settings_page' |
|
271 | - ) ); |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Get the current Font Awesome output settings. |
|
276 | - * |
|
277 | - * @return array The array of settings. |
|
278 | - */ |
|
279 | - public function get_settings() { |
|
280 | - |
|
281 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
282 | - |
|
283 | - $defaults = array( |
|
284 | - 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
285 | - 'version' => '', // latest |
|
286 | - 'enqueue' => '', // front and backend |
|
287 | - 'shims' => '0', // default OFF now in 2020 |
|
288 | - 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
289 | - 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
290 | - 'pro' => '0', // if pro CDN url should be used |
|
291 | - 'kit-url' => '', // the kit url |
|
292 | - ); |
|
293 | - |
|
294 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
295 | - |
|
296 | - /** |
|
297 | - * Filter the Font Awesome settings. |
|
298 | - * |
|
299 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
300 | - */ |
|
301 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * The settings page html output. |
|
307 | - */ |
|
308 | - public function settings_page() { |
|
309 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
310 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
311 | - } |
|
312 | - |
|
313 | - // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
314 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
315 | - $this->get_latest_version( $force_api = true ); |
|
316 | - } |
|
317 | - ?> |
|
24 | + /** |
|
25 | + * A Class to be able to change settings for Font Awesome. |
|
26 | + * |
|
27 | + * Class WP_Font_Awesome_Settings |
|
28 | + * @since 1.0.10 Now able to pass wp.org theme check. |
|
29 | + * @since 1.0.11 Font Awesome Pro now supported. |
|
30 | + * @since 1.0.11 Font Awesome Kits now supported. |
|
31 | + * @since 1.0.13 RTL language support added. |
|
32 | + * @ver 1.0.13 |
|
33 | + * @todo decide how to implement textdomain |
|
34 | + */ |
|
35 | + class WP_Font_Awesome_Settings { |
|
36 | + |
|
37 | + /** |
|
38 | + * Class version version. |
|
39 | + * |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + public $version = '1.0.13'; |
|
43 | + |
|
44 | + /** |
|
45 | + * Class textdomain. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $textdomain = 'font-awesome-settings'; |
|
50 | + |
|
51 | + /** |
|
52 | + * Latest version of Font Awesome at time of publish published. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + public $latest = "5.8.2"; |
|
57 | + |
|
58 | + /** |
|
59 | + * The title. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $name = 'Font Awesome'; |
|
64 | + |
|
65 | + /** |
|
66 | + * Holds the settings values. |
|
67 | + * |
|
68 | + * @var array |
|
69 | + */ |
|
70 | + private $settings; |
|
71 | + |
|
72 | + /** |
|
73 | + * WP_Font_Awesome_Settings instance. |
|
74 | + * |
|
75 | + * @access private |
|
76 | + * @since 1.0.0 |
|
77 | + * @var WP_Font_Awesome_Settings There can be only one! |
|
78 | + */ |
|
79 | + private static $instance = null; |
|
80 | + |
|
81 | + /** |
|
82 | + * Main WP_Font_Awesome_Settings Instance. |
|
83 | + * |
|
84 | + * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
85 | + * |
|
86 | + * @since 1.0.0 |
|
87 | + * @static |
|
88 | + * @return WP_Font_Awesome_Settings - Main instance. |
|
89 | + */ |
|
90 | + public static function instance() { |
|
91 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
92 | + self::$instance = new WP_Font_Awesome_Settings; |
|
93 | + |
|
94 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
95 | + |
|
96 | + if ( is_admin() ) { |
|
97 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
98 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
99 | + } |
|
100 | + |
|
101 | + do_action( 'wp_font_awesome_settings_loaded' ); |
|
102 | + } |
|
103 | + |
|
104 | + return self::$instance; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Initiate the settings and add the required action hooks. |
|
109 | + * |
|
110 | + * @since 1.0.8 Settings name wrong - FIXED |
|
111 | + */ |
|
112 | + public function init() { |
|
113 | + $this->settings = $this->get_settings(); |
|
114 | + |
|
115 | + if ( $this->settings['type'] == 'CSS' ) { |
|
116 | + |
|
117 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
118 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
119 | + } |
|
120 | + |
|
121 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
122 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
123 | + } |
|
124 | + |
|
125 | + } else { |
|
126 | + |
|
127 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
128 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
129 | + } |
|
130 | + |
|
131 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
132 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + // remove font awesome if set to do so |
|
137 | + if ( $this->settings['dequeue'] == '1' ) { |
|
138 | + add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
139 | + } |
|
140 | + |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Adds the Font Awesome styles. |
|
145 | + */ |
|
146 | + public function enqueue_style() { |
|
147 | + // build url |
|
148 | + $url = $this->get_url(); |
|
149 | + |
|
150 | + wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
151 | + wp_register_style( 'font-awesome', $url, array(), null ); |
|
152 | + wp_enqueue_style( 'font-awesome' ); |
|
153 | + |
|
154 | + // RTL language support CSS. |
|
155 | + if ( is_rtl() ) { |
|
156 | + wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
157 | + } |
|
158 | + |
|
159 | + if ( $this->settings['shims'] ) { |
|
160 | + $url = $this->get_url( true ); |
|
161 | + wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
162 | + wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
163 | + wp_enqueue_style( 'font-awesome-shims' ); |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Adds the Font Awesome JS. |
|
169 | + */ |
|
170 | + public function enqueue_scripts() { |
|
171 | + // build url |
|
172 | + $url = $this->get_url(); |
|
173 | + |
|
174 | + $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
175 | + call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
176 | + wp_register_script( 'font-awesome', $url, array(), null ); |
|
177 | + wp_enqueue_script( 'font-awesome' ); |
|
178 | + |
|
179 | + if ( $this->settings['shims'] ) { |
|
180 | + $url = $this->get_url( true ); |
|
181 | + call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
182 | + wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
183 | + wp_enqueue_script( 'font-awesome-shims' ); |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Get the url of the Font Awesome files. |
|
189 | + * |
|
190 | + * @param bool $shims If this is a shim file or not. |
|
191 | + * |
|
192 | + * @return string The url to the file. |
|
193 | + */ |
|
194 | + public function get_url( $shims = false ) { |
|
195 | + $script = $shims ? 'v4-shims' : 'all'; |
|
196 | + $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
197 | + $type = $this->settings['type']; |
|
198 | + $version = $this->settings['version']; |
|
199 | + $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
200 | + $url = ''; |
|
201 | + |
|
202 | + if ( $type == 'KIT' && $kit_url ) { |
|
203 | + if ( $shims ) { |
|
204 | + // if its a kit then we don't add shims here |
|
205 | + return ''; |
|
206 | + } |
|
207 | + $url .= $kit_url; // CDN |
|
208 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
209 | + } else { |
|
210 | + $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
211 | + $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
212 | + $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
213 | + $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
214 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
215 | + } |
|
216 | + |
|
217 | + return $url; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
222 | + * |
|
223 | + * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
224 | + * |
|
225 | + * @param $url |
|
226 | + * @param $original_url |
|
227 | + * @param $_context |
|
228 | + * |
|
229 | + * @return string The filtered url. |
|
230 | + */ |
|
231 | + public function remove_font_awesome( $url, $original_url, $_context ) { |
|
232 | + |
|
233 | + if ( $_context == 'display' |
|
234 | + && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
235 | + && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
236 | + ) {// it's a font-awesome-url (probably) |
|
237 | + |
|
238 | + if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
239 | + if ( $this->settings['type'] == 'JS' ) { |
|
240 | + if ( $this->settings['js-pseudo'] ) { |
|
241 | + $url .= "' data-search-pseudo-elements defer='defer"; |
|
242 | + } else { |
|
243 | + $url .= "' defer='defer"; |
|
244 | + } |
|
245 | + } |
|
246 | + } else { |
|
247 | + $url = ''; // removing the url removes the file |
|
248 | + } |
|
249 | + |
|
250 | + } |
|
251 | + |
|
252 | + return $url; |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Register the database settings with WordPress. |
|
257 | + */ |
|
258 | + public function register_settings() { |
|
259 | + register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Add the WordPress settings menu item. |
|
264 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
265 | + */ |
|
266 | + public function menu_item() { |
|
267 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
268 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
269 | + $this, |
|
270 | + 'settings_page' |
|
271 | + ) ); |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Get the current Font Awesome output settings. |
|
276 | + * |
|
277 | + * @return array The array of settings. |
|
278 | + */ |
|
279 | + public function get_settings() { |
|
280 | + |
|
281 | + $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
282 | + |
|
283 | + $defaults = array( |
|
284 | + 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
285 | + 'version' => '', // latest |
|
286 | + 'enqueue' => '', // front and backend |
|
287 | + 'shims' => '0', // default OFF now in 2020 |
|
288 | + 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
289 | + 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
290 | + 'pro' => '0', // if pro CDN url should be used |
|
291 | + 'kit-url' => '', // the kit url |
|
292 | + ); |
|
293 | + |
|
294 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
295 | + |
|
296 | + /** |
|
297 | + * Filter the Font Awesome settings. |
|
298 | + * |
|
299 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
300 | + */ |
|
301 | + return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * The settings page html output. |
|
307 | + */ |
|
308 | + public function settings_page() { |
|
309 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
310 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
311 | + } |
|
312 | + |
|
313 | + // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
314 | + if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
315 | + $this->get_latest_version( $force_api = true ); |
|
316 | + } |
|
317 | + ?> |
|
318 | 318 | <style> |
319 | 319 | .wpfas-kit-show { |
320 | 320 | display: none; |
@@ -332,10 +332,10 @@ discard block |
||
332 | 332 | <h1><?php echo $this->name; ?></h1> |
333 | 333 | <form method="post" action="options.php"> |
334 | 334 | <?php |
335 | - settings_fields( 'wp-font-awesome-settings' ); |
|
336 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
337 | - $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
|
338 | - ?> |
|
335 | + settings_fields( 'wp-font-awesome-settings' ); |
|
336 | + do_settings_sections( 'wp-font-awesome-settings' ); |
|
337 | + $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
|
338 | + ?> |
|
339 | 339 | <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
340 | 340 | <tr valign="top"> |
341 | 341 | <th scope="row"><label |
@@ -361,12 +361,12 @@ discard block |
||
361 | 361 | value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" |
362 | 362 | placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
363 | 363 | <span><?php |
364 | - echo sprintf( |
|
365 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
366 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
367 | - '</a>' |
|
368 | - ); |
|
369 | - ?></span> |
|
364 | + echo sprintf( |
|
365 | + __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
366 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
367 | + '</a>' |
|
368 | + ); |
|
369 | + ?></span> |
|
370 | 370 | </td> |
371 | 371 | </tr> |
372 | 372 | |
@@ -426,14 +426,14 @@ discard block |
||
426 | 426 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
427 | 427 | value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
428 | 428 | <span><?php |
429 | - echo sprintf( |
|
430 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
431 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>', |
|
432 | - '</a>', |
|
433 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>', |
|
434 | - '</a>' |
|
435 | - ); |
|
436 | - ?></span> |
|
429 | + echo sprintf( |
|
430 | + __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
431 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>', |
|
432 | + '</a>', |
|
433 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>', |
|
434 | + '</a>' |
|
435 | + ); |
|
436 | + ?></span> |
|
437 | 437 | </td> |
438 | 438 | </tr> |
439 | 439 | |
@@ -476,100 +476,100 @@ discard block |
||
476 | 476 | |
477 | 477 | </table> |
478 | 478 | <?php |
479 | - submit_button(); |
|
480 | - ?> |
|
479 | + submit_button(); |
|
480 | + ?> |
|
481 | 481 | </form> |
482 | 482 | |
483 | 483 | <div id="wpfas-version"><?php echo $this->version; ?></div> |
484 | 484 | </div> |
485 | 485 | |
486 | 486 | <?php |
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * Check a version number is valid and if so return it or else return an empty string. |
|
491 | - * |
|
492 | - * @param $version string The version number to check. |
|
493 | - * |
|
494 | - * @since 1.0.6 |
|
495 | - * |
|
496 | - * @return string Either a valid version number or an empty string. |
|
497 | - */ |
|
498 | - public function validate_version_number( $version ) { |
|
499 | - |
|
500 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
501 | - // valid |
|
502 | - } else { |
|
503 | - $version = '';// not validated |
|
504 | - } |
|
505 | - |
|
506 | - return $version; |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - /** |
|
511 | - * Get the latest version of Font Awesome. |
|
512 | - * |
|
513 | - * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
514 | - * |
|
515 | - * @since 1.0.7 |
|
516 | - * @return mixed|string The latest version number found. |
|
517 | - */ |
|
518 | - public function get_latest_version( $force_api = false ) { |
|
519 | - $latest_version = $this->latest; |
|
520 | - |
|
521 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
522 | - |
|
523 | - if ( $cache === false || $force_api ) { // its not set |
|
524 | - $api_ver = $this->get_latest_version_from_api(); |
|
525 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
526 | - $latest_version = $api_ver; |
|
527 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
528 | - } |
|
529 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
530 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
531 | - $latest_version = $cache; |
|
532 | - } |
|
533 | - } |
|
534 | - |
|
535 | - return $latest_version; |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * Get the latest Font Awesome version from the github API. |
|
540 | - * |
|
541 | - * @since 1.0.7 |
|
542 | - * @return string The latest version number or `0` on API fail. |
|
543 | - */ |
|
544 | - public function get_latest_version_from_api() { |
|
545 | - $version = "0"; |
|
546 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
547 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
548 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
549 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
550 | - $version = $api_response['tag_name']; |
|
551 | - } |
|
552 | - } |
|
553 | - |
|
554 | - return $version; |
|
555 | - } |
|
556 | - |
|
557 | - /** |
|
558 | - * Inline CSS for RTL language support. |
|
559 | - * |
|
560 | - * @since 1.0.13 |
|
561 | - * @return string Inline CSS. |
|
562 | - */ |
|
563 | - public function rtl_inline_css() { |
|
564 | - $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
565 | - |
|
566 | - return $inline_css; |
|
567 | - } |
|
568 | - |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * Run the class if found. |
|
573 | - */ |
|
574 | - WP_Font_Awesome_Settings::instance(); |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * Check a version number is valid and if so return it or else return an empty string. |
|
491 | + * |
|
492 | + * @param $version string The version number to check. |
|
493 | + * |
|
494 | + * @since 1.0.6 |
|
495 | + * |
|
496 | + * @return string Either a valid version number or an empty string. |
|
497 | + */ |
|
498 | + public function validate_version_number( $version ) { |
|
499 | + |
|
500 | + if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
501 | + // valid |
|
502 | + } else { |
|
503 | + $version = '';// not validated |
|
504 | + } |
|
505 | + |
|
506 | + return $version; |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + /** |
|
511 | + * Get the latest version of Font Awesome. |
|
512 | + * |
|
513 | + * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
514 | + * |
|
515 | + * @since 1.0.7 |
|
516 | + * @return mixed|string The latest version number found. |
|
517 | + */ |
|
518 | + public function get_latest_version( $force_api = false ) { |
|
519 | + $latest_version = $this->latest; |
|
520 | + |
|
521 | + $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
522 | + |
|
523 | + if ( $cache === false || $force_api ) { // its not set |
|
524 | + $api_ver = $this->get_latest_version_from_api(); |
|
525 | + if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
526 | + $latest_version = $api_ver; |
|
527 | + set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
528 | + } |
|
529 | + } elseif ( $this->validate_version_number( $cache ) ) { |
|
530 | + if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
531 | + $latest_version = $cache; |
|
532 | + } |
|
533 | + } |
|
534 | + |
|
535 | + return $latest_version; |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * Get the latest Font Awesome version from the github API. |
|
540 | + * |
|
541 | + * @since 1.0.7 |
|
542 | + * @return string The latest version number or `0` on API fail. |
|
543 | + */ |
|
544 | + public function get_latest_version_from_api() { |
|
545 | + $version = "0"; |
|
546 | + $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
547 | + if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
548 | + $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
549 | + if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
550 | + $version = $api_response['tag_name']; |
|
551 | + } |
|
552 | + } |
|
553 | + |
|
554 | + return $version; |
|
555 | + } |
|
556 | + |
|
557 | + /** |
|
558 | + * Inline CSS for RTL language support. |
|
559 | + * |
|
560 | + * @since 1.0.13 |
|
561 | + * @return string Inline CSS. |
|
562 | + */ |
|
563 | + public function rtl_inline_css() { |
|
564 | + $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
565 | + |
|
566 | + return $inline_css; |
|
567 | + } |
|
568 | + |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * Run the class if found. |
|
573 | + */ |
|
574 | + WP_Font_Awesome_Settings::instance(); |
|
575 | 575 | } |
576 | 576 | \ No newline at end of file |
@@ -12,14 +12,14 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if (!defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Only add if the class does not already exist. |
21 | 21 | */ |
22 | -if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
|
22 | +if (!class_exists('WP_Font_Awesome_Settings')) { |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * A Class to be able to change settings for Font Awesome. |
@@ -88,17 +88,17 @@ discard block |
||
88 | 88 | * @return WP_Font_Awesome_Settings - Main instance. |
89 | 89 | */ |
90 | 90 | public static function instance() { |
91 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
91 | + if (!isset(self::$instance) && !(self::$instance instanceof WP_Font_Awesome_Settings)) { |
|
92 | 92 | self::$instance = new WP_Font_Awesome_Settings; |
93 | 93 | |
94 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
94 | + add_action('init', array(self::$instance, 'init')); // set settings |
|
95 | 95 | |
96 | - if ( is_admin() ) { |
|
97 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
98 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
96 | + if (is_admin()) { |
|
97 | + add_action('admin_menu', array(self::$instance, 'menu_item')); |
|
98 | + add_action('admin_init', array(self::$instance, 'register_settings')); |
|
99 | 99 | } |
100 | 100 | |
101 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
101 | + do_action('wp_font_awesome_settings_loaded'); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | return self::$instance; |
@@ -112,30 +112,30 @@ discard block |
||
112 | 112 | public function init() { |
113 | 113 | $this->settings = $this->get_settings(); |
114 | 114 | |
115 | - if ( $this->settings['type'] == 'CSS' ) { |
|
115 | + if ($this->settings['type'] == 'CSS') { |
|
116 | 116 | |
117 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
118 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
117 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
118 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
119 | 119 | } |
120 | 120 | |
121 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
122 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
121 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
122 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | } else { |
126 | 126 | |
127 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
128 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
127 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
128 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
129 | 129 | } |
130 | 130 | |
131 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
132 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
131 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
132 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
136 | 136 | // remove font awesome if set to do so |
137 | - if ( $this->settings['dequeue'] == '1' ) { |
|
138 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
137 | + if ($this->settings['dequeue'] == '1') { |
|
138 | + add_action('clean_url', array($this, 'remove_font_awesome'), 5000, 3); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | } |
@@ -147,20 +147,20 @@ discard block |
||
147 | 147 | // build url |
148 | 148 | $url = $this->get_url(); |
149 | 149 | |
150 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
151 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
152 | - wp_enqueue_style( 'font-awesome' ); |
|
150 | + wp_deregister_style('font-awesome'); // deregister in case its already there |
|
151 | + wp_register_style('font-awesome', $url, array(), null); |
|
152 | + wp_enqueue_style('font-awesome'); |
|
153 | 153 | |
154 | 154 | // RTL language support CSS. |
155 | - if ( is_rtl() ) { |
|
156 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
155 | + if (is_rtl()) { |
|
156 | + wp_add_inline_style('font-awesome', $this->rtl_inline_css()); |
|
157 | 157 | } |
158 | 158 | |
159 | - if ( $this->settings['shims'] ) { |
|
160 | - $url = $this->get_url( true ); |
|
161 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
162 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
163 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
159 | + if ($this->settings['shims']) { |
|
160 | + $url = $this->get_url(true); |
|
161 | + wp_deregister_style('font-awesome-shims'); // deregister in case its already there |
|
162 | + wp_register_style('font-awesome-shims', $url, array(), null); |
|
163 | + wp_enqueue_style('font-awesome-shims'); |
|
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
@@ -172,15 +172,15 @@ discard block |
||
172 | 172 | $url = $this->get_url(); |
173 | 173 | |
174 | 174 | $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
175 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
176 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
177 | - wp_enqueue_script( 'font-awesome' ); |
|
178 | - |
|
179 | - if ( $this->settings['shims'] ) { |
|
180 | - $url = $this->get_url( true ); |
|
181 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
182 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
183 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
175 | + call_user_func($deregister_function, 'font-awesome'); // deregister in case its already there |
|
176 | + wp_register_script('font-awesome', $url, array(), null); |
|
177 | + wp_enqueue_script('font-awesome'); |
|
178 | + |
|
179 | + if ($this->settings['shims']) { |
|
180 | + $url = $this->get_url(true); |
|
181 | + call_user_func($deregister_function, 'font-awesome-shims'); // deregister in case its already there |
|
182 | + wp_register_script('font-awesome-shims', $url, array(), null); |
|
183 | + wp_enqueue_script('font-awesome-shims'); |
|
184 | 184 | } |
185 | 185 | } |
186 | 186 | |
@@ -191,16 +191,16 @@ discard block |
||
191 | 191 | * |
192 | 192 | * @return string The url to the file. |
193 | 193 | */ |
194 | - public function get_url( $shims = false ) { |
|
194 | + public function get_url($shims = false) { |
|
195 | 195 | $script = $shims ? 'v4-shims' : 'all'; |
196 | 196 | $sub = $this->settings['pro'] ? 'pro' : 'use'; |
197 | 197 | $type = $this->settings['type']; |
198 | 198 | $version = $this->settings['version']; |
199 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
199 | + $kit_url = $this->settings['kit-url'] ? esc_url($this->settings['kit-url']) : ''; |
|
200 | 200 | $url = ''; |
201 | 201 | |
202 | - if ( $type == 'KIT' && $kit_url ) { |
|
203 | - if ( $shims ) { |
|
202 | + if ($type == 'KIT' && $kit_url) { |
|
203 | + if ($shims) { |
|
204 | 204 | // if its a kit then we don't add shims here |
205 | 205 | return ''; |
206 | 206 | } |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | $url .= "?wpfas=true"; // set our var so our version is not removed |
209 | 209 | } else { |
210 | 210 | $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
211 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
211 | + $url .= !empty($version) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
212 | 212 | $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
213 | 213 | $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
214 | 214 | $url .= "?wpfas=true"; // set our var so our version is not removed |
@@ -228,16 +228,16 @@ discard block |
||
228 | 228 | * |
229 | 229 | * @return string The filtered url. |
230 | 230 | */ |
231 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
231 | + public function remove_font_awesome($url, $original_url, $_context) { |
|
232 | 232 | |
233 | - if ( $_context == 'display' |
|
234 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
235 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
233 | + if ($_context == 'display' |
|
234 | + && (strstr($url, "fontawesome") !== false || strstr($url, "font-awesome") !== false) |
|
235 | + && (strstr($url, ".js") !== false || strstr($url, ".css") !== false) |
|
236 | 236 | ) {// it's a font-awesome-url (probably) |
237 | 237 | |
238 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
239 | - if ( $this->settings['type'] == 'JS' ) { |
|
240 | - if ( $this->settings['js-pseudo'] ) { |
|
238 | + if (strstr($url, "wpfas=true") !== false) { |
|
239 | + if ($this->settings['type'] == 'JS') { |
|
240 | + if ($this->settings['js-pseudo']) { |
|
241 | 241 | $url .= "' data-search-pseudo-elements defer='defer"; |
242 | 242 | } else { |
243 | 243 | $url .= "' defer='defer"; |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * Register the database settings with WordPress. |
257 | 257 | */ |
258 | 258 | public function register_settings() { |
259 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
259 | + register_setting('wp-font-awesome-settings', 'wp-font-awesome-settings'); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -265,10 +265,10 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public function menu_item() { |
267 | 267 | $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
268 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
268 | + call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
269 | 269 | $this, |
270 | 270 | 'settings_page' |
271 | - ) ); |
|
271 | + )); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | */ |
279 | 279 | public function get_settings() { |
280 | 280 | |
281 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
281 | + $db_settings = get_option('wp-font-awesome-settings'); |
|
282 | 282 | |
283 | 283 | $defaults = array( |
284 | 284 | 'type' => 'CSS', // type to use, CSS or JS or KIT |
@@ -291,14 +291,14 @@ discard block |
||
291 | 291 | 'kit-url' => '', // the kit url |
292 | 292 | ); |
293 | 293 | |
294 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
294 | + $settings = wp_parse_args($db_settings, $defaults); |
|
295 | 295 | |
296 | 296 | /** |
297 | 297 | * Filter the Font Awesome settings. |
298 | 298 | * |
299 | 299 | * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
300 | 300 | */ |
301 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
301 | + return $this->settings = apply_filters('wp-font-awesome-settings', $settings, $db_settings, $defaults); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | |
@@ -306,13 +306,13 @@ discard block |
||
306 | 306 | * The settings page html output. |
307 | 307 | */ |
308 | 308 | public function settings_page() { |
309 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
310 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
309 | + if (!current_user_can('manage_options')) { |
|
310 | + wp_die(__('You do not have sufficient permissions to access this page.', 'font-awesome-settings')); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
314 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
315 | - $this->get_latest_version( $force_api = true ); |
|
314 | + if (isset($_REQUEST['force-version-check'])) { |
|
315 | + $this->get_latest_version($force_api = true); |
|
316 | 316 | } |
317 | 317 | ?> |
318 | 318 | <style> |
@@ -332,37 +332,37 @@ discard block |
||
332 | 332 | <h1><?php echo $this->name; ?></h1> |
333 | 333 | <form method="post" action="options.php"> |
334 | 334 | <?php |
335 | - settings_fields( 'wp-font-awesome-settings' ); |
|
336 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
335 | + settings_fields('wp-font-awesome-settings'); |
|
336 | + do_settings_sections('wp-font-awesome-settings'); |
|
337 | 337 | $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
338 | 338 | ?> |
339 | - <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
|
339 | + <table class="form-table wpfas-table-settings <?php echo esc_attr($kit_set); ?>"> |
|
340 | 340 | <tr valign="top"> |
341 | 341 | <th scope="row"><label |
342 | - for="wpfas-type"><?php _e( 'Type', 'font-awesome-settings' ); ?></label></th> |
|
342 | + for="wpfas-type"><?php _e('Type', 'font-awesome-settings'); ?></label></th> |
|
343 | 343 | <td> |
344 | 344 | <select name="wp-font-awesome-settings[type]" id="wpfas-type" |
345 | 345 | onchange="if(this.value=='KIT'){jQuery('.wpfas-table-settings').addClass('wpfas-kit-set');}else{jQuery('.wpfas-table-settings').removeClass('wpfas-kit-set');}"> |
346 | 346 | <option |
347 | - value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e( 'CSS (default)', 'font-awesome-settings' ); ?></option> |
|
348 | - <option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option> |
|
347 | + value="CSS" <?php selected($this->settings['type'], 'CSS'); ?>><?php _e('CSS (default)', 'font-awesome-settings'); ?></option> |
|
348 | + <option value="JS" <?php selected($this->settings['type'], 'JS'); ?>>JS</option> |
|
349 | 349 | <option |
350 | - value="KIT" <?php selected( $this->settings['type'], 'KIT' ); ?>><?php _e( 'Kits (settings managed on fontawesome.com)', 'font-awesome-settings' ); ?></option> |
|
350 | + value="KIT" <?php selected($this->settings['type'], 'KIT'); ?>><?php _e('Kits (settings managed on fontawesome.com)', 'font-awesome-settings'); ?></option> |
|
351 | 351 | </select> |
352 | 352 | </td> |
353 | 353 | </tr> |
354 | 354 | |
355 | 355 | <tr valign="top" class="wpfas-kit-show"> |
356 | 356 | <th scope="row"><label |
357 | - for="wpfas-kit-url"><?php _e( 'Kit URL', 'font-awesome-settings' ); ?></label></th> |
|
357 | + for="wpfas-kit-url"><?php _e('Kit URL', 'font-awesome-settings'); ?></label></th> |
|
358 | 358 | <td> |
359 | 359 | <input class="regular-text" id="wpfas-kit-url" type="url" |
360 | 360 | name="wp-font-awesome-settings[kit-url]" |
361 | - value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" |
|
362 | - placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
|
361 | + value="<?php echo esc_attr($this->settings['kit-url']); ?>" |
|
362 | + placeholder="<?php echo 'https://kit.font'; echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
|
363 | 363 | <span><?php |
364 | 364 | echo sprintf( |
365 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
365 | + __('Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings'), |
|
366 | 366 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
367 | 367 | '</a>' |
368 | 368 | ); |
@@ -372,31 +372,31 @@ discard block |
||
372 | 372 | |
373 | 373 | <tr valign="top" class="wpfas-kit-hide"> |
374 | 374 | <th scope="row"><label |
375 | - for="wpfas-version"><?php _e( 'Version', 'font-awesome-settings' ); ?></label></th> |
|
375 | + for="wpfas-version"><?php _e('Version', 'font-awesome-settings'); ?></label></th> |
|
376 | 376 | <td> |
377 | 377 | <select name="wp-font-awesome-settings[version]" id="wpfas-version"> |
378 | 378 | <option |
379 | - value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo sprintf( __( 'Latest - %s (default)', 'font-awesome-settings' ), $this->get_latest_version() ); ?> |
|
379 | + value="" <?php selected($this->settings['version'], ''); ?>><?php echo sprintf(__('Latest - %s (default)', 'font-awesome-settings'), $this->get_latest_version()); ?> |
|
380 | 380 | </option> |
381 | - <option value="5.6.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>> |
|
381 | + <option value="5.6.0" <?php selected($this->settings['version'], '5.6.0'); ?>> |
|
382 | 382 | 5.6.0 |
383 | 383 | </option> |
384 | - <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>> |
|
384 | + <option value="5.5.0" <?php selected($this->settings['version'], '5.5.0'); ?>> |
|
385 | 385 | 5.5.0 |
386 | 386 | </option> |
387 | - <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>> |
|
387 | + <option value="5.4.0" <?php selected($this->settings['version'], '5.4.0'); ?>> |
|
388 | 388 | 5.4.0 |
389 | 389 | </option> |
390 | - <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>> |
|
390 | + <option value="5.3.0" <?php selected($this->settings['version'], '5.3.0'); ?>> |
|
391 | 391 | 5.3.0 |
392 | 392 | </option> |
393 | - <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>> |
|
393 | + <option value="5.2.0" <?php selected($this->settings['version'], '5.2.0'); ?>> |
|
394 | 394 | 5.2.0 |
395 | 395 | </option> |
396 | - <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>> |
|
396 | + <option value="5.1.0" <?php selected($this->settings['version'], '5.1.0'); ?>> |
|
397 | 397 | 5.1.0 |
398 | 398 | </option> |
399 | - <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>> |
|
399 | + <option value="4.7.0" <?php selected($this->settings['version'], '4.7.0'); ?>> |
|
400 | 400 | 4.7.1 (CSS only) |
401 | 401 | </option> |
402 | 402 | </select> |
@@ -405,29 +405,29 @@ discard block |
||
405 | 405 | |
406 | 406 | <tr valign="top"> |
407 | 407 | <th scope="row"><label |
408 | - for="wpfas-enqueue"><?php _e( 'Enqueue', 'font-awesome-settings' ); ?></label></th> |
|
408 | + for="wpfas-enqueue"><?php _e('Enqueue', 'font-awesome-settings'); ?></label></th> |
|
409 | 409 | <td> |
410 | 410 | <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue"> |
411 | 411 | <option |
412 | - value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)', 'font-awesome-settings' ); ?></option> |
|
412 | + value="" <?php selected($this->settings['enqueue'], ''); ?>><?php _e('Frontend + Backend (default)', 'font-awesome-settings'); ?></option> |
|
413 | 413 | <option |
414 | - value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend', 'font-awesome-settings' ); ?></option> |
|
414 | + value="frontend" <?php selected($this->settings['enqueue'], 'frontend'); ?>><?php _e('Frontend', 'font-awesome-settings'); ?></option> |
|
415 | 415 | <option |
416 | - value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend', 'font-awesome-settings' ); ?></option> |
|
416 | + value="backend" <?php selected($this->settings['enqueue'], 'backend'); ?>><?php _e('Backend', 'font-awesome-settings'); ?></option> |
|
417 | 417 | </select> |
418 | 418 | </td> |
419 | 419 | </tr> |
420 | 420 | |
421 | 421 | <tr valign="top" class="wpfas-kit-hide"> |
422 | 422 | <th scope="row"><label |
423 | - for="wpfas-pro"><?php _e( 'Enable pro', 'font-awesome-settings' ); ?></label></th> |
|
423 | + for="wpfas-pro"><?php _e('Enable pro', 'font-awesome-settings'); ?></label></th> |
|
424 | 424 | <td> |
425 | 425 | <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/> |
426 | 426 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
427 | - value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
|
427 | + value="1" <?php checked($this->settings['pro'], '1'); ?> id="wpfas-pro"/> |
|
428 | 428 | <span><?php |
429 | 429 | echo sprintf( |
430 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
430 | + __('Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings'), |
|
431 | 431 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>', |
432 | 432 | '</a>', |
433 | 433 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>', |
@@ -439,38 +439,38 @@ discard block |
||
439 | 439 | |
440 | 440 | <tr valign="top" class="wpfas-kit-hide"> |
441 | 441 | <th scope="row"><label |
442 | - for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility', 'font-awesome-settings' ); ?></label> |
|
442 | + for="wpfas-shims"><?php _e('Enable v4 shims compatibility', 'font-awesome-settings'); ?></label> |
|
443 | 443 | </th> |
444 | 444 | <td> |
445 | 445 | <input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/> |
446 | 446 | <input type="checkbox" name="wp-font-awesome-settings[shims]" |
447 | - value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims"/> |
|
448 | - <span><?php _e( 'This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings' ); ?></span> |
|
447 | + value="1" <?php checked($this->settings['shims'], '1'); ?> id="wpfas-shims"/> |
|
448 | + <span><?php _e('This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings'); ?></span> |
|
449 | 449 | </td> |
450 | 450 | </tr> |
451 | 451 | |
452 | 452 | <tr valign="top" class="wpfas-kit-hide"> |
453 | 453 | <th scope="row"><label |
454 | - for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)', 'font-awesome-settings' ); ?></label> |
|
454 | + for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)', 'font-awesome-settings'); ?></label> |
|
455 | 455 | </th> |
456 | 456 | <td> |
457 | 457 | <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/> |
458 | 458 | <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]" |
459 | - value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?> |
|
459 | + value="1" <?php checked($this->settings['js-pseudo'], '1'); ?> |
|
460 | 460 | id="wpfas-js-pseudo"/> |
461 | - <span><?php _e( 'Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings' ); ?></span> |
|
461 | + <span><?php _e('Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings'); ?></span> |
|
462 | 462 | </td> |
463 | 463 | </tr> |
464 | 464 | |
465 | 465 | <tr valign="top"> |
466 | 466 | <th scope="row"><label |
467 | - for="wpfas-dequeue"><?php _e( 'Dequeue', 'font-awesome-settings' ); ?></label></th> |
|
467 | + for="wpfas-dequeue"><?php _e('Dequeue', 'font-awesome-settings'); ?></label></th> |
|
468 | 468 | <td> |
469 | 469 | <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/> |
470 | 470 | <input type="checkbox" name="wp-font-awesome-settings[dequeue]" |
471 | - value="1" <?php checked( $this->settings['dequeue'], '1' ); ?> |
|
471 | + value="1" <?php checked($this->settings['dequeue'], '1'); ?> |
|
472 | 472 | id="wpfas-dequeue"/> |
473 | - <span><?php _e( 'This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings' ); ?></span> |
|
473 | + <span><?php _e('This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings'); ?></span> |
|
474 | 474 | </td> |
475 | 475 | </tr> |
476 | 476 | |
@@ -495,12 +495,12 @@ discard block |
||
495 | 495 | * |
496 | 496 | * @return string Either a valid version number or an empty string. |
497 | 497 | */ |
498 | - public function validate_version_number( $version ) { |
|
498 | + public function validate_version_number($version) { |
|
499 | 499 | |
500 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
500 | + if (version_compare($version, '0.0.1', '>=') >= 0) { |
|
501 | 501 | // valid |
502 | 502 | } else { |
503 | - $version = '';// not validated |
|
503 | + $version = ''; // not validated |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | return $version; |
@@ -515,19 +515,19 @@ discard block |
||
515 | 515 | * @since 1.0.7 |
516 | 516 | * @return mixed|string The latest version number found. |
517 | 517 | */ |
518 | - public function get_latest_version( $force_api = false ) { |
|
518 | + public function get_latest_version($force_api = false) { |
|
519 | 519 | $latest_version = $this->latest; |
520 | 520 | |
521 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
521 | + $cache = get_transient('wp-font-awesome-settings-version'); |
|
522 | 522 | |
523 | - if ( $cache === false || $force_api ) { // its not set |
|
523 | + if ($cache === false || $force_api) { // its not set |
|
524 | 524 | $api_ver = $this->get_latest_version_from_api(); |
525 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
525 | + if (version_compare($api_ver, $this->latest, '>=') >= 0) { |
|
526 | 526 | $latest_version = $api_ver; |
527 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
527 | + set_transient('wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS); |
|
528 | 528 | } |
529 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
530 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
529 | + } elseif ($this->validate_version_number($cache)) { |
|
530 | + if (version_compare($cache, $this->latest, '>=') >= 0) { |
|
531 | 531 | $latest_version = $cache; |
532 | 532 | } |
533 | 533 | } |
@@ -543,10 +543,10 @@ discard block |
||
543 | 543 | */ |
544 | 544 | public function get_latest_version_from_api() { |
545 | 545 | $version = "0"; |
546 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
547 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
548 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
549 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
546 | + $response = wp_remote_get("https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest"); |
|
547 | + if (!is_wp_error($response) && is_array($response)) { |
|
548 | + $api_response = json_decode(wp_remote_retrieve_body($response), true); |
|
549 | + if (isset($api_response['tag_name']) && version_compare($api_response['tag_name'], $this->latest, '>=') >= 0 && empty($api_response['prerelease'])) { |
|
550 | 550 | $version = $api_response['tag_name']; |
551 | 551 | } |
552 | 552 | } |
@@ -13,96 +13,96 @@ discard block |
||
13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'paypal'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 1; |
35 | 35 | |
36 | 36 | /** |
37 | - * Stores line items to send to PayPal. |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
37 | + * Stores line items to send to PayPal. |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | 41 | protected $line_items = array(); |
42 | 42 | |
43 | 43 | /** |
44 | - * Endpoint for requests from PayPal. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - protected $notify_url; |
|
49 | - |
|
50 | - /** |
|
51 | - * Endpoint for requests to PayPal. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
44 | + * Endpoint for requests from PayPal. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + protected $notify_url; |
|
49 | + |
|
50 | + /** |
|
51 | + * Endpoint for requests to PayPal. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | 55 | protected $endpoint; |
56 | 56 | |
57 | 57 | /** |
58 | - * Currencies this gateway is allowed for. |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
58 | + * Currencies this gateway is allowed for. |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
63 | 63 | |
64 | 64 | /** |
65 | - * URL to view a transaction. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
65 | + * URL to view a transaction. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
70 | 70 | |
71 | 71 | /** |
72 | - * URL to view a subscription. |
|
73 | - * |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
72 | + * URL to view a subscription. |
|
73 | + * |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
77 | 77 | |
78 | 78 | /** |
79 | - * Class constructor. |
|
80 | - */ |
|
81 | - public function __construct() { |
|
79 | + * Class constructor. |
|
80 | + */ |
|
81 | + public function __construct() { |
|
82 | 82 | |
83 | 83 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
84 | 84 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
85 | 85 | $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
86 | 86 | $this->notify_url = wpinv_get_ipn_url( $this->id ); |
87 | 87 | |
88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
88 | + add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
89 | 89 | add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
90 | - add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
91 | - add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
90 | + add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
91 | + add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
92 | 92 | |
93 | 93 | parent::__construct(); |
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
97 | - * Process Payment. |
|
98 | - * |
|
99 | - * |
|
100 | - * @param WPInv_Invoice $invoice Invoice. |
|
101 | - * @param array $submission_data Posted checkout fields. |
|
102 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
103 | - * @return array |
|
104 | - */ |
|
105 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
97 | + * Process Payment. |
|
98 | + * |
|
99 | + * |
|
100 | + * @param WPInv_Invoice $invoice Invoice. |
|
101 | + * @param array $submission_data Posted checkout fields. |
|
102 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
103 | + * @return array |
|
104 | + */ |
|
105 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
106 | 106 | |
107 | 107 | // Get redirect url. |
108 | 108 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -125,15 +125,15 @@ discard block |
||
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | - * Get the PayPal request URL for an invoice. |
|
129 | - * |
|
130 | - * @param WPInv_Invoice $invoice Invoice object. |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function get_request_url( $invoice ) { |
|
128 | + * Get the PayPal request URL for an invoice. |
|
129 | + * |
|
130 | + * @param WPInv_Invoice $invoice Invoice object. |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function get_request_url( $invoice ) { |
|
134 | 134 | |
135 | 135 | // Endpoint for this request |
136 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
136 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
137 | 137 | |
138 | 138 | // Retrieve paypal args. |
139 | 139 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -146,45 +146,45 @@ discard block |
||
146 | 146 | |
147 | 147 | return add_query_arg( $paypal_args, $this->endpoint ); |
148 | 148 | |
149 | - } |
|
149 | + } |
|
150 | 150 | |
151 | 151 | /** |
152 | - * Get PayPal Args for passing to PP. |
|
153 | - * |
|
154 | - * @param WPInv_Invoice $invoice Invoice object. |
|
155 | - * @return array |
|
156 | - */ |
|
157 | - protected function get_paypal_args( $invoice ) { |
|
152 | + * Get PayPal Args for passing to PP. |
|
153 | + * |
|
154 | + * @param WPInv_Invoice $invoice Invoice object. |
|
155 | + * @return array |
|
156 | + */ |
|
157 | + protected function get_paypal_args( $invoice ) { |
|
158 | 158 | |
159 | 159 | // Whether or not to send the line items as one item. |
160 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
161 | - |
|
162 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
163 | - $force_one_line_item = true; |
|
164 | - } |
|
165 | - |
|
166 | - $paypal_args = apply_filters( |
|
167 | - 'getpaid_paypal_args', |
|
168 | - array_merge( |
|
169 | - $this->get_transaction_args( $invoice ), |
|
170 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
171 | - ), |
|
172 | - $invoice |
|
173 | - ); |
|
174 | - |
|
175 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
160 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
161 | + |
|
162 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
163 | + $force_one_line_item = true; |
|
164 | + } |
|
165 | + |
|
166 | + $paypal_args = apply_filters( |
|
167 | + 'getpaid_paypal_args', |
|
168 | + array_merge( |
|
169 | + $this->get_transaction_args( $invoice ), |
|
170 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
171 | + ), |
|
172 | + $invoice |
|
173 | + ); |
|
174 | + |
|
175 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
179 | - * Get transaction args for paypal request. |
|
180 | - * |
|
181 | - * @param WPInv_Invoice $invoice Invoice object. |
|
182 | - * @return array |
|
183 | - */ |
|
184 | - protected function get_transaction_args( $invoice ) { |
|
185 | - |
|
186 | - $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
187 | - return array( |
|
179 | + * Get transaction args for paypal request. |
|
180 | + * |
|
181 | + * @param WPInv_Invoice $invoice Invoice object. |
|
182 | + * @return array |
|
183 | + */ |
|
184 | + protected function get_transaction_args( $invoice ) { |
|
185 | + |
|
186 | + $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
187 | + return array( |
|
188 | 188 | 'cmd' => '_cart', |
189 | 189 | 'business' => $email, |
190 | 190 | 'no_shipping' => '1', |
@@ -209,16 +209,16 @@ discard block |
||
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | - * Get line item args for paypal request. |
|
213 | - * |
|
214 | - * @param WPInv_Invoice $invoice Invoice object. |
|
215 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
216 | - * @return array |
|
217 | - */ |
|
218 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
212 | + * Get line item args for paypal request. |
|
213 | + * |
|
214 | + * @param WPInv_Invoice $invoice Invoice object. |
|
215 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
216 | + * @return array |
|
217 | + */ |
|
218 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
219 | 219 | |
220 | 220 | // Maybe send invoice as a single item. |
221 | - if ( $force_one_line_item ) { |
|
221 | + if ( $force_one_line_item ) { |
|
222 | 222 | return $this->get_line_item_args_single_item( $invoice ); |
223 | 223 | } |
224 | 224 | |
@@ -238,129 +238,129 @@ discard block |
||
238 | 238 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
239 | 239 | } |
240 | 240 | |
241 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
241 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
242 | 242 | |
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | - * Get line item args for paypal request as a single line item. |
|
247 | - * |
|
248 | - * @param WPInv_Invoice $invoice Invoice object. |
|
249 | - * @return array |
|
250 | - */ |
|
251 | - protected function get_line_item_args_single_item( $invoice ) { |
|
252 | - $this->delete_line_items(); |
|
246 | + * Get line item args for paypal request as a single line item. |
|
247 | + * |
|
248 | + * @param WPInv_Invoice $invoice Invoice object. |
|
249 | + * @return array |
|
250 | + */ |
|
251 | + protected function get_line_item_args_single_item( $invoice ) { |
|
252 | + $this->delete_line_items(); |
|
253 | 253 | |
254 | 254 | $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
255 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
255 | + $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
256 | 256 | |
257 | - return $this->get_line_items(); |
|
257 | + return $this->get_line_items(); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
261 | - * Return all line items. |
|
262 | - */ |
|
263 | - protected function get_line_items() { |
|
264 | - return $this->line_items; |
|
265 | - } |
|
261 | + * Return all line items. |
|
262 | + */ |
|
263 | + protected function get_line_items() { |
|
264 | + return $this->line_items; |
|
265 | + } |
|
266 | 266 | |
267 | 267 | /** |
268 | - * Remove all line items. |
|
269 | - */ |
|
270 | - protected function delete_line_items() { |
|
271 | - $this->line_items = array(); |
|
268 | + * Remove all line items. |
|
269 | + */ |
|
270 | + protected function delete_line_items() { |
|
271 | + $this->line_items = array(); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
275 | - * Prepare line items to send to paypal. |
|
276 | - * |
|
277 | - * @param WPInv_Invoice $invoice Invoice object. |
|
278 | - */ |
|
279 | - protected function prepare_line_items( $invoice ) { |
|
280 | - $this->delete_line_items(); |
|
281 | - |
|
282 | - // Items. |
|
283 | - foreach ( $invoice->get_items() as $item ) { |
|
284 | - $amount = $item->get_price(); |
|
285 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
286 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
275 | + * Prepare line items to send to paypal. |
|
276 | + * |
|
277 | + * @param WPInv_Invoice $invoice Invoice object. |
|
278 | + */ |
|
279 | + protected function prepare_line_items( $invoice ) { |
|
280 | + $this->delete_line_items(); |
|
281 | + |
|
282 | + // Items. |
|
283 | + foreach ( $invoice->get_items() as $item ) { |
|
284 | + $amount = $item->get_price(); |
|
285 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
286 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | // Fees. |
290 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
290 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
291 | 291 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
292 | 292 | } |
293 | 293 | |
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | - * Add PayPal Line Item. |
|
298 | - * |
|
299 | - * @param string $item_name Item name. |
|
300 | - * @param float $quantity Item quantity. |
|
301 | - * @param float $amount Amount. |
|
302 | - * @param string $item_number Item number. |
|
303 | - */ |
|
304 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
305 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
306 | - |
|
307 | - $item = apply_filters( |
|
308 | - 'getpaid_paypal_line_item', |
|
309 | - array( |
|
310 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
311 | - 'quantity' => (float) $quantity, |
|
312 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
313 | - 'item_number' => $item_number, |
|
314 | - ), |
|
315 | - $item_name, |
|
316 | - $quantity, |
|
317 | - $amount, |
|
318 | - $item_number |
|
319 | - ); |
|
320 | - |
|
321 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
297 | + * Add PayPal Line Item. |
|
298 | + * |
|
299 | + * @param string $item_name Item name. |
|
300 | + * @param float $quantity Item quantity. |
|
301 | + * @param float $amount Amount. |
|
302 | + * @param string $item_number Item number. |
|
303 | + */ |
|
304 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
305 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
306 | + |
|
307 | + $item = apply_filters( |
|
308 | + 'getpaid_paypal_line_item', |
|
309 | + array( |
|
310 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
311 | + 'quantity' => (float) $quantity, |
|
312 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
313 | + 'item_number' => $item_number, |
|
314 | + ), |
|
315 | + $item_name, |
|
316 | + $quantity, |
|
317 | + $amount, |
|
318 | + $item_number |
|
319 | + ); |
|
320 | + |
|
321 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
322 | 322 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
323 | 323 | |
324 | 324 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
325 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
326 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
325 | + $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
326 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
330 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
331 | - * |
|
332 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
333 | - * |
|
334 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
335 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
336 | - * @return array |
|
337 | - */ |
|
338 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
339 | - $max_paypal_length = 2083; |
|
340 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
341 | - |
|
342 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
343 | - return $paypal_args; |
|
344 | - } |
|
345 | - |
|
346 | - return apply_filters( |
|
347 | - 'getpaid_paypal_args', |
|
348 | - array_merge( |
|
349 | - $this->get_transaction_args( $invoice ), |
|
350 | - $this->get_line_item_args( $invoice, true ) |
|
351 | - ), |
|
352 | - $invoice |
|
353 | - ); |
|
330 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
331 | + * |
|
332 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
333 | + * |
|
334 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
335 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
336 | + * @return array |
|
337 | + */ |
|
338 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
339 | + $max_paypal_length = 2083; |
|
340 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
341 | + |
|
342 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
343 | + return $paypal_args; |
|
344 | + } |
|
345 | + |
|
346 | + return apply_filters( |
|
347 | + 'getpaid_paypal_args', |
|
348 | + array_merge( |
|
349 | + $this->get_transaction_args( $invoice ), |
|
350 | + $this->get_line_item_args( $invoice, true ) |
|
351 | + ), |
|
352 | + $invoice |
|
353 | + ); |
|
354 | 354 | |
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
358 | - * Processes recurring invoices. |
|
359 | - * |
|
360 | - * @param array $paypal_args PayPal args. |
|
361 | - * @param WPInv_Invoice $invoice Invoice object. |
|
362 | - */ |
|
363 | - public function process_subscription( $paypal_args, $invoice ) { |
|
358 | + * Processes recurring invoices. |
|
359 | + * |
|
360 | + * @param array $paypal_args PayPal args. |
|
361 | + * @param WPInv_Invoice $invoice Invoice object. |
|
362 | + */ |
|
363 | + public function process_subscription( $paypal_args, $invoice ) { |
|
364 | 364 | |
365 | 365 | // Make sure this is a subscription. |
366 | 366 | if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
@@ -385,11 +385,11 @@ discard block |
||
385 | 385 | |
386 | 386 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
387 | 387 | |
388 | - // Trial period length. |
|
389 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
388 | + // Trial period length. |
|
389 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
390 | 390 | |
391 | - // Trial period. |
|
392 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
391 | + // Trial period. |
|
392 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
393 | 393 | |
394 | 394 | } else if ( $initial_amount != $recurring_amount ) { |
395 | 395 | |
@@ -412,40 +412,40 @@ discard block |
||
412 | 412 | } |
413 | 413 | |
414 | 414 | // We have a recurring payment |
415 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
415 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
416 | 416 | |
417 | - // Subscription price |
|
418 | - $paypal_args['a3'] = $recurring_amount; |
|
417 | + // Subscription price |
|
418 | + $paypal_args['a3'] = $recurring_amount; |
|
419 | 419 | |
420 | - // Subscription duration |
|
421 | - $paypal_args['p3'] = $interval; |
|
420 | + // Subscription duration |
|
421 | + $paypal_args['p3'] = $interval; |
|
422 | 422 | |
423 | - // Subscription period |
|
424 | - $paypal_args['t3'] = $period; |
|
423 | + // Subscription period |
|
424 | + $paypal_args['t3'] = $period; |
|
425 | 425 | |
426 | 426 | } |
427 | 427 | |
428 | 428 | // Recurring payments |
429 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
429 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
430 | 430 | |
431 | - // Non-recurring payments |
|
432 | - $paypal_args['src'] = 0; |
|
431 | + // Non-recurring payments |
|
432 | + $paypal_args['src'] = 0; |
|
433 | 433 | |
434 | - } else { |
|
434 | + } else { |
|
435 | 435 | |
436 | - $paypal_args['src'] = 1; |
|
436 | + $paypal_args['src'] = 1; |
|
437 | 437 | |
438 | - if ( $bill_times > 0 ) { |
|
438 | + if ( $bill_times > 0 ) { |
|
439 | 439 | |
440 | - // An initial period is being used to charge a sign-up fee |
|
441 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
442 | - $bill_times--; |
|
443 | - } |
|
440 | + // An initial period is being used to charge a sign-up fee |
|
441 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
442 | + $bill_times--; |
|
443 | + } |
|
444 | 444 | |
445 | 445 | // Make sure it's not over the max of 52 |
446 | 446 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
447 | 447 | |
448 | - } |
|
448 | + } |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | // Force return URL so that order description & instructions display |
@@ -461,19 +461,19 @@ discard block |
||
461 | 461 | } |
462 | 462 | |
463 | 463 | return apply_filters( |
464 | - 'getpaid_paypal_subscription_args', |
|
465 | - $paypal_args, |
|
466 | - $invoice |
|
464 | + 'getpaid_paypal_subscription_args', |
|
465 | + $paypal_args, |
|
466 | + $invoice |
|
467 | 467 | ); |
468 | 468 | |
469 | 469 | } |
470 | 470 | |
471 | 471 | /** |
472 | - * Processes ipns and marks payments as complete. |
|
473 | - * |
|
474 | - * @return void |
|
475 | - */ |
|
476 | - public function verify_ipn() { |
|
472 | + * Processes ipns and marks payments as complete. |
|
473 | + * |
|
474 | + * @return void |
|
475 | + */ |
|
476 | + public function verify_ipn() { |
|
477 | 477 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
478 | 478 | } |
479 | 479 | |
@@ -483,19 +483,19 @@ discard block |
||
483 | 483 | public function sandbox_notice() { |
484 | 484 | |
485 | 485 | return sprintf( |
486 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
487 | - '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
488 | - '</a>' |
|
489 | - ); |
|
486 | + __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
487 | + '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
488 | + '</a>' |
|
489 | + ); |
|
490 | 490 | |
491 | 491 | } |
492 | 492 | |
493 | - /** |
|
494 | - * Filters the gateway settings. |
|
495 | - * |
|
496 | - * @param array $admin_settings |
|
497 | - */ |
|
498 | - public function admin_settings( $admin_settings ) { |
|
493 | + /** |
|
494 | + * Filters the gateway settings. |
|
495 | + * |
|
496 | + * @param array $admin_settings |
|
497 | + */ |
|
498 | + public function admin_settings( $admin_settings ) { |
|
499 | 499 | |
500 | 500 | $currencies = sprintf( |
501 | 501 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -505,39 +505,39 @@ discard block |
||
505 | 505 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
506 | 506 | $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
507 | 507 | |
508 | - // Access tokens. |
|
509 | - $live_email = wpinv_get_option( 'paypal_email' ); |
|
510 | - $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
511 | - |
|
512 | - $admin_settings['paypal_connect'] = array( |
|
513 | - 'type' => 'raw_html', |
|
514 | - 'id' => 'paypal_connect', |
|
515 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
516 | - 'desc' => sprintf( |
|
517 | - '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s', |
|
518 | - esc_url( self::get_connect_url( false ) ), |
|
519 | - __( 'Connect to PayPal', 'invoicing' ), |
|
520 | - esc_url( self::get_connect_url( true ) ), |
|
521 | - __( 'Connect to PayPal Sandox', 'invoicing' ), |
|
522 | - $this->get_js() |
|
523 | - ), |
|
524 | - ); |
|
508 | + // Access tokens. |
|
509 | + $live_email = wpinv_get_option( 'paypal_email' ); |
|
510 | + $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
511 | + |
|
512 | + $admin_settings['paypal_connect'] = array( |
|
513 | + 'type' => 'raw_html', |
|
514 | + 'id' => 'paypal_connect', |
|
515 | + 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
516 | + 'desc' => sprintf( |
|
517 | + '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s', |
|
518 | + esc_url( self::get_connect_url( false ) ), |
|
519 | + __( 'Connect to PayPal', 'invoicing' ), |
|
520 | + esc_url( self::get_connect_url( true ) ), |
|
521 | + __( 'Connect to PayPal Sandox', 'invoicing' ), |
|
522 | + $this->get_js() |
|
523 | + ), |
|
524 | + ); |
|
525 | 525 | |
526 | 526 | $admin_settings['paypal_email'] = array( |
527 | 527 | 'type' => 'text', |
528 | - 'class' => 'live-auth-data', |
|
528 | + 'class' => 'live-auth-data', |
|
529 | 529 | 'id' => 'paypal_email', |
530 | 530 | 'name' => __( 'Live Email Address', 'invoicing' ), |
531 | 531 | 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
532 | 532 | ); |
533 | 533 | |
534 | - $admin_settings['paypal_sandbox_email'] = array( |
|
534 | + $admin_settings['paypal_sandbox_email'] = array( |
|
535 | 535 | 'type' => 'text', |
536 | - 'class' => 'sandbox-auth-data', |
|
536 | + 'class' => 'sandbox-auth-data', |
|
537 | 537 | 'id' => 'paypal_sandbox_email', |
538 | 538 | 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
539 | 539 | 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
540 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
540 | + 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
541 | 541 | ); |
542 | 542 | |
543 | 543 | $admin_settings['paypal_ipn_url'] = array( |
@@ -549,29 +549,29 @@ discard block |
||
549 | 549 | 'readonly' => true, |
550 | 550 | ); |
551 | 551 | |
552 | - return $admin_settings; |
|
553 | - } |
|
552 | + return $admin_settings; |
|
553 | + } |
|
554 | 554 | |
555 | - /** |
|
556 | - * Retrieves the PayPal connect URL when using the setup wizzard. |
|
557 | - * |
|
558 | - * |
|
555 | + /** |
|
556 | + * Retrieves the PayPal connect URL when using the setup wizzard. |
|
557 | + * |
|
558 | + * |
|
559 | 559 | * @param array $data |
560 | 560 | * @return string |
561 | - */ |
|
562 | - public static function maybe_get_connect_url( $url = '', $data ) { |
|
563 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
564 | - } |
|
565 | - |
|
566 | - /** |
|
567 | - * Retrieves the PayPal connect URL. |
|
568 | - * |
|
569 | - * |
|
561 | + */ |
|
562 | + public static function maybe_get_connect_url( $url = '', $data ) { |
|
563 | + return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
564 | + } |
|
565 | + |
|
566 | + /** |
|
567 | + * Retrieves the PayPal connect URL. |
|
568 | + * |
|
569 | + * |
|
570 | 570 | * @param bool $is_sandbox |
571 | - * @param string $redirect |
|
571 | + * @param string $redirect |
|
572 | 572 | * @return string |
573 | - */ |
|
574 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
573 | + */ |
|
574 | + public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
575 | 575 | |
576 | 576 | $redirect_url = add_query_arg( |
577 | 577 | array( |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | 'tab' => 'gateways', |
582 | 582 | 'section' => 'paypal', |
583 | 583 | 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
584 | - 'redirect' => urlencode( $redirect ), |
|
584 | + 'redirect' => urlencode( $redirect ), |
|
585 | 585 | ), |
586 | 586 | admin_url( 'admin.php' ) |
587 | 587 | ); |
@@ -596,12 +596,12 @@ discard block |
||
596 | 596 | |
597 | 597 | } |
598 | 598 | |
599 | - /** |
|
600 | - * Generates settings page js. |
|
601 | - * |
|
599 | + /** |
|
600 | + * Generates settings page js. |
|
601 | + * |
|
602 | 602 | * @return void |
603 | - */ |
|
604 | - public static function get_js() { |
|
603 | + */ |
|
604 | + public static function get_js() { |
|
605 | 605 | ob_start(); |
606 | 606 | ?> |
607 | 607 | <script> |
@@ -637,72 +637,72 @@ discard block |
||
637 | 637 | return ob_get_clean(); |
638 | 638 | } |
639 | 639 | |
640 | - /** |
|
641 | - * Connects to PayPal. |
|
642 | - * |
|
643 | - * @param array $data Connection data. |
|
644 | - * @return void |
|
645 | - */ |
|
646 | - public function connect_paypal( $data ) { |
|
647 | - |
|
648 | - $sandbox = $this->is_sandbox(); |
|
649 | - $data = wp_unslash( $data ); |
|
650 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
651 | - |
|
652 | - if ( isset( $data['live_mode'] ) ) { |
|
653 | - $sandbox = empty( $data['live_mode'] ); |
|
654 | - } |
|
655 | - |
|
656 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
657 | - wpinv_update_option( 'paypal_active', 1 ); |
|
658 | - |
|
659 | - if ( ! empty( $data['error_description'] ) ) { |
|
660 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
661 | - } else { |
|
662 | - |
|
663 | - // Retrieve the user info. |
|
664 | - $user_info = wp_remote_get( |
|
665 | - ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
666 | - array( |
|
667 | - |
|
668 | - 'headers' => array( |
|
669 | - 'Authorization' => 'Bearer ' . $access_token, |
|
670 | - 'Content-type' => 'application/json', |
|
671 | - ) |
|
672 | - |
|
673 | - ) |
|
674 | - ); |
|
675 | - |
|
676 | - if ( is_wp_error( $user_info ) ) { |
|
677 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
678 | - } else { |
|
679 | - |
|
680 | - // Create application. |
|
681 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
682 | - |
|
683 | - if ( $sandbox ) { |
|
684 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
685 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
686 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
687 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
688 | - } else { |
|
689 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
690 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
691 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
692 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
693 | - } |
|
694 | - |
|
695 | - } |
|
696 | - |
|
697 | - } |
|
698 | - |
|
699 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
700 | - |
|
701 | - if ( isset( $data['step'] ) ) { |
|
702 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
703 | - } |
|
704 | - wp_redirect( $redirect ); |
|
705 | - exit; |
|
706 | - } |
|
640 | + /** |
|
641 | + * Connects to PayPal. |
|
642 | + * |
|
643 | + * @param array $data Connection data. |
|
644 | + * @return void |
|
645 | + */ |
|
646 | + public function connect_paypal( $data ) { |
|
647 | + |
|
648 | + $sandbox = $this->is_sandbox(); |
|
649 | + $data = wp_unslash( $data ); |
|
650 | + $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
651 | + |
|
652 | + if ( isset( $data['live_mode'] ) ) { |
|
653 | + $sandbox = empty( $data['live_mode'] ); |
|
654 | + } |
|
655 | + |
|
656 | + wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
657 | + wpinv_update_option( 'paypal_active', 1 ); |
|
658 | + |
|
659 | + if ( ! empty( $data['error_description'] ) ) { |
|
660 | + getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
661 | + } else { |
|
662 | + |
|
663 | + // Retrieve the user info. |
|
664 | + $user_info = wp_remote_get( |
|
665 | + ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
666 | + array( |
|
667 | + |
|
668 | + 'headers' => array( |
|
669 | + 'Authorization' => 'Bearer ' . $access_token, |
|
670 | + 'Content-type' => 'application/json', |
|
671 | + ) |
|
672 | + |
|
673 | + ) |
|
674 | + ); |
|
675 | + |
|
676 | + if ( is_wp_error( $user_info ) ) { |
|
677 | + getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
678 | + } else { |
|
679 | + |
|
680 | + // Create application. |
|
681 | + $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
682 | + |
|
683 | + if ( $sandbox ) { |
|
684 | + wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
685 | + wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
686 | + set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
687 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
688 | + } else { |
|
689 | + wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
690 | + wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
691 | + set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
692 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
693 | + } |
|
694 | + |
|
695 | + } |
|
696 | + |
|
697 | + } |
|
698 | + |
|
699 | + $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
700 | + |
|
701 | + if ( isset( $data['step'] ) ) { |
|
702 | + $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
703 | + } |
|
704 | + wp_redirect( $redirect ); |
|
705 | + exit; |
|
706 | + } |
|
707 | 707 | |
708 | 708 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Paypal Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' ); |
|
27 | + protected $supports = array('subscription', 'sandbox', 'single_subscription_group'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @var array |
61 | 61 | */ |
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
62 | + public $currencies = array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR'); |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * URL to view a transaction. |
@@ -80,15 +80,15 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function __construct() { |
82 | 82 | |
83 | - $this->title = __( 'PayPal Standard', 'invoicing' ); |
|
84 | - $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
|
85 | - $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
|
86 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
83 | + $this->title = __('PayPal Standard', 'invoicing'); |
|
84 | + $this->method_title = __('PayPal Standard', 'invoicing'); |
|
85 | + $this->checkout_button_text = __('Proceed to PayPal', 'invoicing'); |
|
86 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
87 | 87 | |
88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
89 | - add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
90 | - add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
91 | - add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
88 | + add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2); |
|
89 | + add_filter('getpaid_paypal_sandbox_notice', array($this, 'sandbox_notice')); |
|
90 | + add_filter('getpaid_get_paypal_connect_url', array($this, 'maybe_get_connect_url'), 10, 2); |
|
91 | + add_action('getpaid_authenticated_admin_action_connect_paypal', array($this, 'connect_paypal')); |
|
92 | 92 | |
93 | 93 | parent::__construct(); |
94 | 94 | } |
@@ -102,16 +102,16 @@ discard block |
||
102 | 102 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
103 | 103 | * @return array |
104 | 104 | */ |
105 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
105 | + public function process_payment($invoice, $submission_data, $submission) { |
|
106 | 106 | |
107 | 107 | // Get redirect url. |
108 | - $paypal_redirect = $this->get_request_url( $invoice ); |
|
108 | + $paypal_redirect = $this->get_request_url($invoice); |
|
109 | 109 | |
110 | 110 | // Add a note about the request url. |
111 | 111 | $invoice->add_note( |
112 | 112 | sprintf( |
113 | - __( 'Redirecting to PayPal: %s', 'invoicing' ), |
|
114 | - esc_url( $paypal_redirect ) |
|
113 | + __('Redirecting to PayPal: %s', 'invoicing'), |
|
114 | + esc_url($paypal_redirect) |
|
115 | 115 | ), |
116 | 116 | false, |
117 | 117 | false, |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | ); |
120 | 120 | |
121 | 121 | // Redirect to PayPal |
122 | - wp_redirect( $paypal_redirect ); |
|
122 | + wp_redirect($paypal_redirect); |
|
123 | 123 | exit; |
124 | 124 | |
125 | 125 | } |
@@ -130,21 +130,21 @@ discard block |
||
130 | 130 | * @param WPInv_Invoice $invoice Invoice object. |
131 | 131 | * @return string |
132 | 132 | */ |
133 | - public function get_request_url( $invoice ) { |
|
133 | + public function get_request_url($invoice) { |
|
134 | 134 | |
135 | 135 | // Endpoint for this request |
136 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
136 | + $this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
137 | 137 | |
138 | 138 | // Retrieve paypal args. |
139 | - $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
|
139 | + $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode'); |
|
140 | 140 | |
141 | - if ( $invoice->is_recurring() ) { |
|
141 | + if ($invoice->is_recurring()) { |
|
142 | 142 | $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US'; |
143 | 143 | } else { |
144 | 144 | $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US'; |
145 | 145 | } |
146 | 146 | |
147 | - return add_query_arg( $paypal_args, $this->endpoint ); |
|
147 | + return add_query_arg($paypal_args, $this->endpoint); |
|
148 | 148 | |
149 | 149 | } |
150 | 150 | |
@@ -154,25 +154,25 @@ discard block |
||
154 | 154 | * @param WPInv_Invoice $invoice Invoice object. |
155 | 155 | * @return array |
156 | 156 | */ |
157 | - protected function get_paypal_args( $invoice ) { |
|
157 | + protected function get_paypal_args($invoice) { |
|
158 | 158 | |
159 | 159 | // Whether or not to send the line items as one item. |
160 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
160 | + $force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', true, $invoice); |
|
161 | 161 | |
162 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
162 | + if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) { |
|
163 | 163 | $force_one_line_item = true; |
164 | 164 | } |
165 | 165 | |
166 | 166 | $paypal_args = apply_filters( |
167 | 167 | 'getpaid_paypal_args', |
168 | 168 | array_merge( |
169 | - $this->get_transaction_args( $invoice ), |
|
170 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
169 | + $this->get_transaction_args($invoice), |
|
170 | + $this->get_line_item_args($invoice, $force_one_line_item) |
|
171 | 171 | ), |
172 | 172 | $invoice |
173 | 173 | ); |
174 | 174 | |
175 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
175 | + return $this->fix_request_length($invoice, $paypal_args); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | * @param WPInv_Invoice $invoice Invoice object. |
182 | 182 | * @return array |
183 | 183 | */ |
184 | - protected function get_transaction_args( $invoice ) { |
|
184 | + protected function get_transaction_args($invoice) { |
|
185 | 185 | |
186 | - $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
186 | + $email = $this->is_sandbox($invoice) ? wpinv_get_option('paypal_sandbox_email', wpinv_get_option('paypal_email', '')) : wpinv_get_option('paypal_email', ''); |
|
187 | 187 | return array( |
188 | 188 | 'cmd' => '_cart', |
189 | 189 | 'business' => $email, |
@@ -194,16 +194,16 @@ discard block |
||
194 | 194 | 'rm' => is_ssl() ? 2 : 1, |
195 | 195 | 'upload' => 1, |
196 | 196 | 'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal |
197 | - 'return' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
198 | - 'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ), |
|
199 | - 'notify_url' => getpaid_limit_length( $this->notify_url, 255 ), |
|
200 | - 'invoice' => getpaid_limit_length( $invoice->get_number(), 127 ), |
|
197 | + 'return' => esc_url_raw($this->get_return_url($invoice)), |
|
198 | + 'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()), |
|
199 | + 'notify_url' => getpaid_limit_length($this->notify_url, 255), |
|
200 | + 'invoice' => getpaid_limit_length($invoice->get_number(), 127), |
|
201 | 201 | 'custom' => $invoice->get_id(), |
202 | - 'first_name' => getpaid_limit_length( $invoice->get_first_name(), 32 ), |
|
203 | - 'last_name' => getpaid_limit_length( $invoice->get_last_name(), 64 ), |
|
204 | - 'country' => getpaid_limit_length( $invoice->get_country(), 2 ), |
|
205 | - 'email' => getpaid_limit_length( $invoice->get_email(), 127 ), |
|
206 | - 'cbt' => get_bloginfo( 'name' ) |
|
202 | + 'first_name' => getpaid_limit_length($invoice->get_first_name(), 32), |
|
203 | + 'last_name' => getpaid_limit_length($invoice->get_last_name(), 64), |
|
204 | + 'country' => getpaid_limit_length($invoice->get_country(), 2), |
|
205 | + 'email' => getpaid_limit_length($invoice->get_email(), 127), |
|
206 | + 'cbt' => get_bloginfo('name') |
|
207 | 207 | ); |
208 | 208 | |
209 | 209 | } |
@@ -215,30 +215,30 @@ discard block |
||
215 | 215 | * @param bool $force_one_line_item Create only one item for this invoice. |
216 | 216 | * @return array |
217 | 217 | */ |
218 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
218 | + protected function get_line_item_args($invoice, $force_one_line_item = false) { |
|
219 | 219 | |
220 | 220 | // Maybe send invoice as a single item. |
221 | - if ( $force_one_line_item ) { |
|
222 | - return $this->get_line_item_args_single_item( $invoice ); |
|
221 | + if ($force_one_line_item) { |
|
222 | + return $this->get_line_item_args_single_item($invoice); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | // Send each line item individually. |
226 | 226 | $line_item_args = array(); |
227 | 227 | |
228 | 228 | // Prepare line items. |
229 | - $this->prepare_line_items( $invoice ); |
|
229 | + $this->prepare_line_items($invoice); |
|
230 | 230 | |
231 | 231 | // Add taxes to the cart |
232 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
233 | - $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 ); |
|
232 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
233 | + $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | // Add discount. |
237 | - if ( $invoice->get_total_discount() > 0 ) { |
|
238 | - $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
|
237 | + if ($invoice->get_total_discount() > 0) { |
|
238 | + $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2); |
|
239 | 239 | } |
240 | 240 | |
241 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
241 | + return array_merge($line_item_args, $this->get_line_items()); |
|
242 | 242 | |
243 | 243 | } |
244 | 244 | |
@@ -248,11 +248,11 @@ discard block |
||
248 | 248 | * @param WPInv_Invoice $invoice Invoice object. |
249 | 249 | * @return array |
250 | 250 | */ |
251 | - protected function get_line_item_args_single_item( $invoice ) { |
|
251 | + protected function get_line_item_args_single_item($invoice) { |
|
252 | 252 | $this->delete_line_items(); |
253 | 253 | |
254 | - $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
255 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
254 | + $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
255 | + $this->add_line_item($item_name, 1, wpinv_round_amount((float) $invoice->get_total(), 2, true), $invoice->get_id()); |
|
256 | 256 | |
257 | 257 | return $this->get_line_items(); |
258 | 258 | } |
@@ -276,19 +276,19 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @param WPInv_Invoice $invoice Invoice object. |
278 | 278 | */ |
279 | - protected function prepare_line_items( $invoice ) { |
|
279 | + protected function prepare_line_items($invoice) { |
|
280 | 280 | $this->delete_line_items(); |
281 | 281 | |
282 | 282 | // Items. |
283 | - foreach ( $invoice->get_items() as $item ) { |
|
283 | + foreach ($invoice->get_items() as $item) { |
|
284 | 284 | $amount = $item->get_price(); |
285 | 285 | $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
286 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
286 | + $this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id()); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | // Fees. |
290 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
291 | - $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
|
290 | + foreach ($invoice->get_fees() as $fee => $data) { |
|
291 | + $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee'])); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | } |
@@ -301,15 +301,15 @@ discard block |
||
301 | 301 | * @param float $amount Amount. |
302 | 302 | * @param string $item_number Item number. |
303 | 303 | */ |
304 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
305 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
304 | + protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') { |
|
305 | + $index = (count($this->line_items) / 4) + 1; |
|
306 | 306 | |
307 | 307 | $item = apply_filters( |
308 | 308 | 'getpaid_paypal_line_item', |
309 | 309 | array( |
310 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
310 | + 'item_name' => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'), |
|
311 | 311 | 'quantity' => (float) $quantity, |
312 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
312 | + 'amount' => wpinv_sanitize_amount((float) $amount, 2), |
|
313 | 313 | 'item_number' => $item_number, |
314 | 314 | ), |
315 | 315 | $item_name, |
@@ -318,12 +318,12 @@ discard block |
||
318 | 318 | $item_number |
319 | 319 | ); |
320 | 320 | |
321 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
322 | - $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
|
321 | + $this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127); |
|
322 | + $this->line_items['quantity_' . $index] = $item['quantity']; |
|
323 | 323 | |
324 | 324 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
325 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
326 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
325 | + $this->line_items['amount_' . $index] = $item['amount'] * $item['quantity']; |
|
326 | + $this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -335,19 +335,19 @@ discard block |
||
335 | 335 | * @param array $paypal_args Arguments sent to Paypal in the request. |
336 | 336 | * @return array |
337 | 337 | */ |
338 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
338 | + protected function fix_request_length($invoice, $paypal_args) { |
|
339 | 339 | $max_paypal_length = 2083; |
340 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
340 | + $query_candidate = http_build_query($paypal_args, '', '&'); |
|
341 | 341 | |
342 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
342 | + if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) { |
|
343 | 343 | return $paypal_args; |
344 | 344 | } |
345 | 345 | |
346 | 346 | return apply_filters( |
347 | 347 | 'getpaid_paypal_args', |
348 | 348 | array_merge( |
349 | - $this->get_transaction_args( $invoice ), |
|
350 | - $this->get_line_item_args( $invoice, true ) |
|
349 | + $this->get_transaction_args($invoice), |
|
350 | + $this->get_line_item_args($invoice, true) |
|
351 | 351 | ), |
352 | 352 | $invoice |
353 | 353 | ); |
@@ -360,10 +360,10 @@ discard block |
||
360 | 360 | * @param array $paypal_args PayPal args. |
361 | 361 | * @param WPInv_Invoice $invoice Invoice object. |
362 | 362 | */ |
363 | - public function process_subscription( $paypal_args, $invoice ) { |
|
363 | + public function process_subscription($paypal_args, $invoice) { |
|
364 | 364 | |
365 | 365 | // Make sure this is a subscription. |
366 | - if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
|
366 | + if (!$invoice->is_recurring() || !$subscription = getpaid_get_invoice_subscription($invoice)) { |
|
367 | 367 | return $paypal_args; |
368 | 368 | } |
369 | 369 | |
@@ -371,17 +371,17 @@ discard block |
||
371 | 371 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
372 | 372 | |
373 | 373 | // Subscription name. |
374 | - $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
374 | + $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
375 | 375 | |
376 | 376 | // Get subscription args. |
377 | - $period = strtoupper( substr( $subscription->get_period(), 0, 1) ); |
|
377 | + $period = strtoupper(substr($subscription->get_period(), 0, 1)); |
|
378 | 378 | $interval = (int) $subscription->get_frequency(); |
379 | 379 | $bill_times = (int) $subscription->get_bill_times(); |
380 | - $initial_amount = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 ); |
|
381 | - $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
|
382 | - $subscription_item = $invoice->get_recurring( true ); |
|
380 | + $initial_amount = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2); |
|
381 | + $recurring_amount = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2); |
|
382 | + $subscription_item = $invoice->get_recurring(true); |
|
383 | 383 | |
384 | - if ( $subscription_item->has_free_trial() ) { |
|
384 | + if ($subscription_item->has_free_trial()) { |
|
385 | 385 | |
386 | 386 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
387 | 387 | |
@@ -391,28 +391,28 @@ discard block |
||
391 | 391 | // Trial period. |
392 | 392 | $paypal_args['t1'] = $subscription_item->get_trial_period(); |
393 | 393 | |
394 | - } else if ( $initial_amount != $recurring_amount ) { |
|
394 | + } else if ($initial_amount != $recurring_amount) { |
|
395 | 395 | |
396 | 396 | // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period. |
397 | 397 | |
398 | - if ( 1 == $bill_times ) { |
|
398 | + if (1 == $bill_times) { |
|
399 | 399 | $param_number = 3; |
400 | 400 | } else { |
401 | 401 | $param_number = 1; |
402 | 402 | } |
403 | 403 | |
404 | - $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0; |
|
404 | + $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0; |
|
405 | 405 | |
406 | 406 | // Sign Up interval |
407 | - $paypal_args[ 'p' . $param_number ] = $interval; |
|
407 | + $paypal_args['p' . $param_number] = $interval; |
|
408 | 408 | |
409 | 409 | // Sign Up unit of duration |
410 | - $paypal_args[ 't' . $param_number ] = $period; |
|
410 | + $paypal_args['t' . $param_number] = $period; |
|
411 | 411 | |
412 | 412 | } |
413 | 413 | |
414 | 414 | // We have a recurring payment |
415 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
415 | + if (!isset($param_number) || 1 == $param_number) { |
|
416 | 416 | |
417 | 417 | // Subscription price |
418 | 418 | $paypal_args['a3'] = $recurring_amount; |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | } |
427 | 427 | |
428 | 428 | // Recurring payments |
429 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
429 | + if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) { |
|
430 | 430 | |
431 | 431 | // Non-recurring payments |
432 | 432 | $paypal_args['src'] = 0; |
@@ -435,15 +435,15 @@ discard block |
||
435 | 435 | |
436 | 436 | $paypal_args['src'] = 1; |
437 | 437 | |
438 | - if ( $bill_times > 0 ) { |
|
438 | + if ($bill_times > 0) { |
|
439 | 439 | |
440 | 440 | // An initial period is being used to charge a sign-up fee |
441 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
441 | + if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) { |
|
442 | 442 | $bill_times--; |
443 | 443 | } |
444 | 444 | |
445 | 445 | // Make sure it's not over the max of 52 |
446 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
446 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
447 | 447 | |
448 | 448 | } |
449 | 449 | } |
@@ -452,10 +452,10 @@ discard block |
||
452 | 452 | $paypal_args['rm'] = 2; |
453 | 453 | |
454 | 454 | // Get rid of redudant items. |
455 | - foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) { |
|
455 | + foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) { |
|
456 | 456 | |
457 | - if ( isset( $paypal_args[ $arg ] ) ) { |
|
458 | - unset( $paypal_args[ $arg ] ); |
|
457 | + if (isset($paypal_args[$arg])) { |
|
458 | + unset($paypal_args[$arg]); |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | } |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | * @return void |
475 | 475 | */ |
476 | 476 | public function verify_ipn() { |
477 | - new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
|
477 | + new GetPaid_Paypal_Gateway_IPN_Handler($this); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | /** |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | public function sandbox_notice() { |
484 | 484 | |
485 | 485 | return sprintf( |
486 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
486 | + __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
487 | 487 | '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
488 | 488 | '</a>' |
489 | 489 | ); |
@@ -495,30 +495,30 @@ discard block |
||
495 | 495 | * |
496 | 496 | * @param array $admin_settings |
497 | 497 | */ |
498 | - public function admin_settings( $admin_settings ) { |
|
498 | + public function admin_settings($admin_settings) { |
|
499 | 499 | |
500 | 500 | $currencies = sprintf( |
501 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
502 | - implode( ', ', $this->currencies ) |
|
501 | + __('Supported Currencies: %s', 'invoicing'), |
|
502 | + implode(', ', $this->currencies) |
|
503 | 503 | ); |
504 | 504 | |
505 | 505 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
506 | - $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
|
506 | + $admin_settings['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing'); |
|
507 | 507 | |
508 | 508 | // Access tokens. |
509 | - $live_email = wpinv_get_option( 'paypal_email' ); |
|
510 | - $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
509 | + $live_email = wpinv_get_option('paypal_email'); |
|
510 | + $sandbox_email = wpinv_get_option('paypal_sandbox_email'); |
|
511 | 511 | |
512 | 512 | $admin_settings['paypal_connect'] = array( |
513 | 513 | 'type' => 'raw_html', |
514 | 514 | 'id' => 'paypal_connect', |
515 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
515 | + 'name' => __('Connect to PayPal', 'invoicing'), |
|
516 | 516 | 'desc' => sprintf( |
517 | 517 | '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s', |
518 | - esc_url( self::get_connect_url( false ) ), |
|
519 | - __( 'Connect to PayPal', 'invoicing' ), |
|
520 | - esc_url( self::get_connect_url( true ) ), |
|
521 | - __( 'Connect to PayPal Sandox', 'invoicing' ), |
|
518 | + esc_url(self::get_connect_url(false)), |
|
519 | + __('Connect to PayPal', 'invoicing'), |
|
520 | + esc_url(self::get_connect_url(true)), |
|
521 | + __('Connect to PayPal Sandox', 'invoicing'), |
|
522 | 522 | $this->get_js() |
523 | 523 | ), |
524 | 524 | ); |
@@ -527,25 +527,25 @@ discard block |
||
527 | 527 | 'type' => 'text', |
528 | 528 | 'class' => 'live-auth-data', |
529 | 529 | 'id' => 'paypal_email', |
530 | - 'name' => __( 'Live Email Address', 'invoicing' ), |
|
531 | - 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
|
530 | + 'name' => __('Live Email Address', 'invoicing'), |
|
531 | + 'desc' => __('The email address of your PayPal account.', 'invoicing'), |
|
532 | 532 | ); |
533 | 533 | |
534 | 534 | $admin_settings['paypal_sandbox_email'] = array( |
535 | 535 | 'type' => 'text', |
536 | 536 | 'class' => 'sandbox-auth-data', |
537 | 537 | 'id' => 'paypal_sandbox_email', |
538 | - 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
|
539 | - 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
|
540 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
538 | + 'name' => __('Sandbox Email Address', 'invoicing'), |
|
539 | + 'desc' => __('The email address of your sandbox PayPal account.', 'invoicing'), |
|
540 | + 'std' => wpinv_get_option('paypal_email', ''), |
|
541 | 541 | ); |
542 | 542 | |
543 | 543 | $admin_settings['paypal_ipn_url'] = array( |
544 | 544 | 'type' => 'ipn_url', |
545 | 545 | 'id' => 'paypal_ipn_url', |
546 | - 'name' => __( 'IPN Url', 'invoicing' ), |
|
546 | + 'name' => __('IPN Url', 'invoicing'), |
|
547 | 547 | 'std' => $this->notify_url, |
548 | - 'desc' => __( "If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing' ) . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
548 | + 'desc' => __("If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing') . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
549 | 549 | 'readonly' => true, |
550 | 550 | ); |
551 | 551 | |
@@ -559,8 +559,8 @@ discard block |
||
559 | 559 | * @param array $data |
560 | 560 | * @return string |
561 | 561 | */ |
562 | - public static function maybe_get_connect_url( $url = '', $data ) { |
|
563 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
562 | + public static function maybe_get_connect_url($url = '', $data) { |
|
563 | + return self::get_connect_url(false, urldecode($data['redirect'])); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
@@ -571,25 +571,25 @@ discard block |
||
571 | 571 | * @param string $redirect |
572 | 572 | * @return string |
573 | 573 | */ |
574 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
574 | + public static function get_connect_url($is_sandbox, $redirect = '') { |
|
575 | 575 | |
576 | 576 | $redirect_url = add_query_arg( |
577 | 577 | array( |
578 | 578 | 'getpaid-admin-action' => 'connect_paypal', |
579 | 579 | 'page' => 'wpinv-settings', |
580 | - 'live_mode' => (int) empty( $is_sandbox ), |
|
580 | + 'live_mode' => (int) empty($is_sandbox), |
|
581 | 581 | 'tab' => 'gateways', |
582 | 582 | 'section' => 'paypal', |
583 | - 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
|
584 | - 'redirect' => urlencode( $redirect ), |
|
583 | + 'getpaid-nonce' => wp_create_nonce('getpaid-nonce'), |
|
584 | + 'redirect' => urlencode($redirect), |
|
585 | 585 | ), |
586 | - admin_url( 'admin.php' ) |
|
586 | + admin_url('admin.php') |
|
587 | 587 | ); |
588 | 588 | |
589 | 589 | return add_query_arg( |
590 | 590 | array( |
591 | - 'live_mode' => (int) empty( $is_sandbox ), |
|
592 | - 'redirect_url' => urlencode( str_replace( '&', '&', $redirect_url ) ) |
|
591 | + 'live_mode' => (int) empty($is_sandbox), |
|
592 | + 'redirect_url' => urlencode(str_replace('&', '&', $redirect_url)) |
|
593 | 593 | ), |
594 | 594 | 'https://ayecode.io/oauth/paypal' |
595 | 595 | ); |
@@ -643,26 +643,26 @@ discard block |
||
643 | 643 | * @param array $data Connection data. |
644 | 644 | * @return void |
645 | 645 | */ |
646 | - public function connect_paypal( $data ) { |
|
646 | + public function connect_paypal($data) { |
|
647 | 647 | |
648 | 648 | $sandbox = $this->is_sandbox(); |
649 | - $data = wp_unslash( $data ); |
|
650 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
649 | + $data = wp_unslash($data); |
|
650 | + $access_token = empty($data['access_token']) ? '' : sanitize_text_field($data['access_token']); |
|
651 | 651 | |
652 | - if ( isset( $data['live_mode'] ) ) { |
|
653 | - $sandbox = empty( $data['live_mode'] ); |
|
652 | + if (isset($data['live_mode'])) { |
|
653 | + $sandbox = empty($data['live_mode']); |
|
654 | 654 | } |
655 | 655 | |
656 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
657 | - wpinv_update_option( 'paypal_active', 1 ); |
|
656 | + wpinv_update_option('paypal_sandbox', (int) $sandbox); |
|
657 | + wpinv_update_option('paypal_active', 1); |
|
658 | 658 | |
659 | - if ( ! empty( $data['error_description'] ) ) { |
|
660 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
659 | + if (!empty($data['error_description'])) { |
|
660 | + getpaid_admin()->show_error(wp_kses_post(urldecode($data['error_description']))); |
|
661 | 661 | } else { |
662 | 662 | |
663 | 663 | // Retrieve the user info. |
664 | 664 | $user_info = wp_remote_get( |
665 | - ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
665 | + !$sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
666 | 666 | array( |
667 | 667 | |
668 | 668 | 'headers' => array( |
@@ -673,35 +673,35 @@ discard block |
||
673 | 673 | ) |
674 | 674 | ); |
675 | 675 | |
676 | - if ( is_wp_error( $user_info ) ) { |
|
677 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
676 | + if (is_wp_error($user_info)) { |
|
677 | + getpaid_admin()->show_error(wp_kses_post($user_info->get_error_message())); |
|
678 | 678 | } else { |
679 | 679 | |
680 | 680 | // Create application. |
681 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
681 | + $user_info = json_decode(wp_remote_retrieve_body($user_info)); |
|
682 | 682 | |
683 | - if ( $sandbox ) { |
|
684 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
685 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
686 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
687 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
683 | + if ($sandbox) { |
|
684 | + wpinv_update_option('paypal_sandbox_email', sanitize_email($user_info->emails[0]->value)); |
|
685 | + wpinv_update_option('paypal_sandbox_refresh_token', sanitize_text_field(urldecode($data['refresh_token']))); |
|
686 | + set_transient('getpaid_paypal_sandbox_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']); |
|
687 | + getpaid_admin()->show_success(__('Successfully connected your PayPal sandbox account', 'invoicing')); |
|
688 | 688 | } else { |
689 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
690 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
691 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
692 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
689 | + wpinv_update_option('paypal_email', sanitize_email($user_info->emails[0]->value)); |
|
690 | + wpinv_update_option('paypal_refresh_token', sanitize_text_field(urldecode($data['refresh_token']))); |
|
691 | + set_transient('getpaid_paypal_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']); |
|
692 | + getpaid_admin()->show_success(__('Successfully connected your PayPal account', 'invoicing')); |
|
693 | 693 | } |
694 | 694 | |
695 | 695 | } |
696 | 696 | |
697 | 697 | } |
698 | 698 | |
699 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
699 | + $redirect = empty($data['redirect']) ? admin_url('admin.php?page=wpinv-settings&tab=gateways§ion=paypal') : urldecode($data['redirect']); |
|
700 | 700 | |
701 | - if ( isset( $data['step'] ) ) { |
|
702 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
701 | + if (isset($data['step'])) { |
|
702 | + $redirect = add_query_arg('step', $data['step'], $redirect); |
|
703 | 703 | } |
704 | - wp_redirect( $redirect ); |
|
704 | + wp_redirect($redirect); |
|
705 | 705 | exit; |
706 | 706 | } |
707 | 707 |
@@ -9,41 +9,41 @@ discard block |
||
9 | 9 | * @version 1.0.19 |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | return array( |
15 | 15 | |
16 | 16 | array( |
17 | 17 | 'type' => 'heading', |
18 | - 'name' => __( 'Heading', 'invoicing' ), |
|
18 | + 'name' => __('Heading', 'invoicing'), |
|
19 | 19 | 'defaults' => array( |
20 | 20 | 'level' => 'h2', |
21 | - 'text' => __( 'Heading', 'invoicing' ), |
|
21 | + 'text' => __('Heading', 'invoicing'), |
|
22 | 22 | ) |
23 | 23 | ), |
24 | 24 | |
25 | 25 | array( |
26 | 26 | 'type' => 'paragraph', |
27 | - 'name' => __( 'Paragraph', 'invoicing' ), |
|
27 | + 'name' => __('Paragraph', 'invoicing'), |
|
28 | 28 | 'defaults' => array( |
29 | - 'text' => __( 'Paragraph text', 'invoicing' ), |
|
29 | + 'text' => __('Paragraph text', 'invoicing'), |
|
30 | 30 | ) |
31 | 31 | ), |
32 | 32 | |
33 | 33 | array( |
34 | 34 | 'type' => 'alert', |
35 | - 'name' => __( 'Alert', 'invoicing' ), |
|
35 | + 'name' => __('Alert', 'invoicing'), |
|
36 | 36 | 'defaults' => array( |
37 | 37 | 'value' => '', |
38 | 38 | 'class' => 'alert-warning', |
39 | - 'text' => __( 'Alert', 'invoicing' ), |
|
39 | + 'text' => __('Alert', 'invoicing'), |
|
40 | 40 | 'dismissible' => false, |
41 | 41 | ) |
42 | 42 | ), |
43 | 43 | |
44 | 44 | array( |
45 | 45 | 'type' => 'separator', |
46 | - 'name' => __( 'Separator', 'invoicing' ), |
|
46 | + 'name' => __('Separator', 'invoicing'), |
|
47 | 47 | 'defaults' => array( |
48 | 48 | 'value' => '', |
49 | 49 | ), |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | |
52 | 52 | array( |
53 | 53 | 'type' => 'text', |
54 | - 'name' => __( 'Text Input', 'invoicing' ), |
|
54 | + 'name' => __('Text Input', 'invoicing'), |
|
55 | 55 | 'defaults' => array( |
56 | - 'placeholder' => __( 'Enter some text', 'invoicing' ), |
|
56 | + 'placeholder' => __('Enter some text', 'invoicing'), |
|
57 | 57 | 'value' => '', |
58 | - 'label' => __( 'Field Label', 'invoicing' ), |
|
58 | + 'label' => __('Field Label', 'invoicing'), |
|
59 | 59 | 'description' => '', |
60 | 60 | 'required' => false, |
61 | 61 | ) |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | |
64 | 64 | array( |
65 | 65 | 'type' => 'textarea', |
66 | - 'name' => __( 'Textarea', 'invoicing' ), |
|
66 | + 'name' => __('Textarea', 'invoicing'), |
|
67 | 67 | 'defaults' => array( |
68 | - 'placeholder' => __( 'Enter your text here', 'invoicing' ), |
|
68 | + 'placeholder' => __('Enter your text here', 'invoicing'), |
|
69 | 69 | 'value' => '', |
70 | - 'label' => __( 'Textarea Label', 'invoicing' ), |
|
70 | + 'label' => __('Textarea Label', 'invoicing'), |
|
71 | 71 | 'description' => '', |
72 | 72 | 'required' => false, |
73 | 73 | ) |
@@ -75,27 +75,27 @@ discard block |
||
75 | 75 | |
76 | 76 | array( |
77 | 77 | 'type' => 'select', |
78 | - 'name' => __( 'Dropdown', 'invoicing' ), |
|
78 | + 'name' => __('Dropdown', 'invoicing'), |
|
79 | 79 | 'defaults' => array( |
80 | - 'placeholder' => __( 'Select a value', 'invoicing' ), |
|
80 | + 'placeholder' => __('Select a value', 'invoicing'), |
|
81 | 81 | 'value' => '', |
82 | - 'label' => __( 'Dropdown Label', 'invoicing' ), |
|
82 | + 'label' => __('Dropdown Label', 'invoicing'), |
|
83 | 83 | 'description' => '', |
84 | 84 | 'required' => false, |
85 | 85 | 'options' => array( |
86 | - esc_attr__( 'Option One', 'invoicing' ), |
|
87 | - esc_attr__( 'Option Two', 'invoicing' ), |
|
88 | - esc_attr__( 'Option Three', 'invoicing' ) |
|
86 | + esc_attr__('Option One', 'invoicing'), |
|
87 | + esc_attr__('Option Two', 'invoicing'), |
|
88 | + esc_attr__('Option Three', 'invoicing') |
|
89 | 89 | ), |
90 | 90 | ) |
91 | 91 | ), |
92 | 92 | |
93 | 93 | array( |
94 | 94 | 'type' => 'checkbox', |
95 | - 'name' => __( 'Checkbox', 'invoicing' ), |
|
95 | + 'name' => __('Checkbox', 'invoicing'), |
|
96 | 96 | 'defaults' => array( |
97 | 97 | 'value' => '', |
98 | - 'label' => __( 'Checkbox Label', 'invoicing' ), |
|
98 | + 'label' => __('Checkbox Label', 'invoicing'), |
|
99 | 99 | 'description' => '', |
100 | 100 | 'required' => false, |
101 | 101 | ) |
@@ -103,23 +103,23 @@ discard block |
||
103 | 103 | |
104 | 104 | array( |
105 | 105 | 'type' => 'radio', |
106 | - 'name' => __( 'Radio', 'invoicing' ), |
|
106 | + 'name' => __('Radio', 'invoicing'), |
|
107 | 107 | 'defaults' => array( |
108 | - 'label' => __( 'Select one choice', 'invoicing' ), |
|
108 | + 'label' => __('Select one choice', 'invoicing'), |
|
109 | 109 | 'options' => array( |
110 | - esc_attr__( 'Choice One', 'invoicing' ), |
|
111 | - esc_attr__( 'Choice Two', 'invoicing' ), |
|
112 | - esc_attr__( 'Choice Three', 'invoicing' ) |
|
110 | + esc_attr__('Choice One', 'invoicing'), |
|
111 | + esc_attr__('Choice Two', 'invoicing'), |
|
112 | + esc_attr__('Choice Three', 'invoicing') |
|
113 | 113 | ), |
114 | 114 | ) |
115 | 115 | ), |
116 | 116 | |
117 | 117 | array( |
118 | 118 | 'type' => 'date', |
119 | - 'name' => __( 'Date', 'invoicing' ), |
|
119 | + 'name' => __('Date', 'invoicing'), |
|
120 | 120 | 'defaults' => array( |
121 | 121 | 'value' => '', |
122 | - 'label' => __( 'Date', 'invoicing' ), |
|
122 | + 'label' => __('Date', 'invoicing'), |
|
123 | 123 | 'description' => '', |
124 | 124 | 'required' => false, |
125 | 125 | ) |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | |
128 | 128 | array( |
129 | 129 | 'type' => 'time', |
130 | - 'name' => __( 'Time', 'invoicing' ), |
|
130 | + 'name' => __('Time', 'invoicing'), |
|
131 | 131 | 'defaults' => array( |
132 | 132 | 'value' => '', |
133 | - 'label' => __( 'Time', 'invoicing' ), |
|
133 | + 'label' => __('Time', 'invoicing'), |
|
134 | 134 | 'description' => '', |
135 | 135 | 'required' => false, |
136 | 136 | ) |
@@ -138,11 +138,11 @@ discard block |
||
138 | 138 | |
139 | 139 | array( |
140 | 140 | 'type' => 'number', |
141 | - 'name' => __( 'Number', 'invoicing' ), |
|
141 | + 'name' => __('Number', 'invoicing'), |
|
142 | 142 | 'defaults' => array( |
143 | 143 | 'placeholder' => '', |
144 | 144 | 'value' => '', |
145 | - 'label' => __( 'Number', 'invoicing' ), |
|
145 | + 'label' => __('Number', 'invoicing'), |
|
146 | 146 | 'description' => '', |
147 | 147 | 'required' => false, |
148 | 148 | ) |
@@ -150,11 +150,11 @@ discard block |
||
150 | 150 | |
151 | 151 | array( |
152 | 152 | 'type' => 'website', |
153 | - 'name' => __( 'Website', 'invoicing' ), |
|
153 | + 'name' => __('Website', 'invoicing'), |
|
154 | 154 | 'defaults' => array( |
155 | 155 | 'placeholder' => 'http://example.com', |
156 | 156 | 'value' => '', |
157 | - 'label' => __( 'Website', 'invoicing' ), |
|
157 | + 'label' => __('Website', 'invoicing'), |
|
158 | 158 | 'description' => '', |
159 | 159 | 'required' => false, |
160 | 160 | ) |
@@ -162,11 +162,11 @@ discard block |
||
162 | 162 | |
163 | 163 | array( |
164 | 164 | 'type' => 'email', |
165 | - 'name' => __( 'Email', 'invoicing' ), |
|
165 | + 'name' => __('Email', 'invoicing'), |
|
166 | 166 | 'defaults' => array( |
167 | 167 | 'placeholder' => '[email protected]', |
168 | 168 | 'value' => '', |
169 | - 'label' => __( 'Email Address', 'invoicing' ), |
|
169 | + 'label' => __('Email Address', 'invoicing'), |
|
170 | 170 | 'description' => '', |
171 | 171 | 'required' => false, |
172 | 172 | ) |
@@ -174,18 +174,18 @@ discard block |
||
174 | 174 | |
175 | 175 | array( |
176 | 176 | 'type' => 'address', |
177 | - 'name' => __( 'Address', 'invoicing' ), |
|
177 | + 'name' => __('Address', 'invoicing'), |
|
178 | 178 | 'defaults' => array( |
179 | 179 | |
180 | 180 | 'address_type' => 'billing', |
181 | - 'billing_address_title' => __( 'Billing Address', 'invoicing' ), |
|
182 | - 'shipping_address_title' => __( 'Shipping Address', 'invoicing' ), |
|
183 | - 'shipping_address_toggle' => __( 'Same billing & shipping address.', 'invoicing' ), |
|
181 | + 'billing_address_title' => __('Billing Address', 'invoicing'), |
|
182 | + 'shipping_address_title' => __('Shipping Address', 'invoicing'), |
|
183 | + 'shipping_address_toggle' => __('Same billing & shipping address.', 'invoicing'), |
|
184 | 184 | 'fields' => array( |
185 | 185 | array( |
186 | 186 | 'placeholder' => 'Jon', |
187 | 187 | 'value' => '', |
188 | - 'label' => __( 'First Name', 'invoicing' ), |
|
188 | + 'label' => __('First Name', 'invoicing'), |
|
189 | 189 | 'description' => '', |
190 | 190 | 'required' => false, |
191 | 191 | 'visible' => true, |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | array( |
197 | 197 | 'placeholder' => 'Snow', |
198 | 198 | 'value' => '', |
199 | - 'label' => __( 'Last Name', 'invoicing' ), |
|
199 | + 'label' => __('Last Name', 'invoicing'), |
|
200 | 200 | 'description' => '', |
201 | 201 | 'required' => false, |
202 | 202 | 'visible' => true, |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | array( |
208 | 208 | 'placeholder' => '', |
209 | 209 | 'value' => '', |
210 | - 'label' => __( 'Address', 'invoicing' ), |
|
210 | + 'label' => __('Address', 'invoicing'), |
|
211 | 211 | 'description' => '', |
212 | 212 | 'required' => false, |
213 | 213 | 'visible' => true, |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | array( |
219 | 219 | 'placeholder' => '', |
220 | 220 | 'value' => '', |
221 | - 'label' => __( 'City', 'invoicing' ), |
|
221 | + 'label' => __('City', 'invoicing'), |
|
222 | 222 | 'description' => '', |
223 | 223 | 'required' => false, |
224 | 224 | 'visible' => true, |
@@ -227,9 +227,9 @@ discard block |
||
227 | 227 | ), |
228 | 228 | |
229 | 229 | array( |
230 | - 'placeholder' => __( 'Select your country' ), |
|
230 | + 'placeholder' => __('Select your country'), |
|
231 | 231 | 'value' => '', |
232 | - 'label' => __( 'Country', 'invoicing' ), |
|
232 | + 'label' => __('Country', 'invoicing'), |
|
233 | 233 | 'description' => '', |
234 | 234 | 'required' => false, |
235 | 235 | 'visible' => true, |
@@ -238,9 +238,9 @@ discard block |
||
238 | 238 | ), |
239 | 239 | |
240 | 240 | array( |
241 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
241 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
242 | 242 | 'value' => '', |
243 | - 'label' => __( 'State / Province', 'invoicing' ), |
|
243 | + 'label' => __('State / Province', 'invoicing'), |
|
244 | 244 | 'description' => '', |
245 | 245 | 'required' => false, |
246 | 246 | 'visible' => true, |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | array( |
252 | 252 | 'placeholder' => '', |
253 | 253 | 'value' => '', |
254 | - 'label' => __( 'ZIP / Postcode', 'invoicing' ), |
|
254 | + 'label' => __('ZIP / Postcode', 'invoicing'), |
|
255 | 255 | 'description' => '', |
256 | 256 | 'required' => false, |
257 | 257 | 'visible' => true, |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | array( |
263 | 263 | 'placeholder' => '', |
264 | 264 | 'value' => '', |
265 | - 'label' => __( 'Phone', 'invoicing' ), |
|
265 | + 'label' => __('Phone', 'invoicing'), |
|
266 | 266 | 'description' => '', |
267 | 267 | 'required' => false, |
268 | 268 | 'visible' => true, |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | array( |
274 | 274 | 'placeholder' => '', |
275 | 275 | 'value' => '', |
276 | - 'label' => __( 'Company', 'invoicing' ), |
|
276 | + 'label' => __('Company', 'invoicing'), |
|
277 | 277 | 'description' => '', |
278 | 278 | 'required' => false, |
279 | 279 | 'visible' => false, |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | array( |
285 | 285 | 'placeholder' => '', |
286 | 286 | 'value' => '', |
287 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
287 | + 'label' => __('Company ID', 'invoicing'), |
|
288 | 288 | 'description' => '', |
289 | 289 | 'required' => false, |
290 | 290 | 'visible' => false, |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | array( |
296 | 296 | 'placeholder' => '', |
297 | 297 | 'value' => '', |
298 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
298 | + 'label' => __('VAT Number', 'invoicing'), |
|
299 | 299 | 'description' => '', |
300 | 300 | 'required' => false, |
301 | 301 | 'visible' => false, |
@@ -308,11 +308,11 @@ discard block |
||
308 | 308 | |
309 | 309 | array( |
310 | 310 | 'type' => 'billing_email', |
311 | - 'name' => __( 'Billing Email', 'invoicing' ), |
|
311 | + 'name' => __('Billing Email', 'invoicing'), |
|
312 | 312 | 'defaults' => array( |
313 | 313 | 'placeholder' => '[email protected]', |
314 | 314 | 'value' => '', |
315 | - 'label' => __( 'Billing Email', 'invoicing' ), |
|
315 | + 'label' => __('Billing Email', 'invoicing'), |
|
316 | 316 | 'description' => '', |
317 | 317 | 'premade' => true, |
318 | 318 | ) |
@@ -320,18 +320,18 @@ discard block |
||
320 | 320 | |
321 | 321 | array( |
322 | 322 | 'type' => 'discount', |
323 | - 'name' => __( 'Discount Input', 'invoicing' ), |
|
323 | + 'name' => __('Discount Input', 'invoicing'), |
|
324 | 324 | 'defaults' => array( |
325 | 325 | 'value' => '', |
326 | - 'input_label' => __( 'Coupon Code', 'invoicing' ), |
|
327 | - 'button_label' => __( 'Apply Coupon', 'invoicing' ), |
|
328 | - 'description' => __( 'Have a discount code? Enter it above.', 'invoicing' ), |
|
326 | + 'input_label' => __('Coupon Code', 'invoicing'), |
|
327 | + 'button_label' => __('Apply Coupon', 'invoicing'), |
|
328 | + 'description' => __('Have a discount code? Enter it above.', 'invoicing'), |
|
329 | 329 | ) |
330 | 330 | ), |
331 | 331 | |
332 | 332 | array( |
333 | 333 | 'type' => 'items', |
334 | - 'name' => __( 'Items', 'invoicing' ), |
|
334 | + 'name' => __('Items', 'invoicing'), |
|
335 | 335 | 'defaults' => array( |
336 | 336 | 'value' => '', |
337 | 337 | 'items_type' => 'total', |
@@ -343,22 +343,22 @@ discard block |
||
343 | 343 | |
344 | 344 | array( |
345 | 345 | 'type' => 'price_input', |
346 | - 'name' => __( 'Price Input', 'invoicing' ), |
|
346 | + 'name' => __('Price Input', 'invoicing'), |
|
347 | 347 | 'defaults' => array( |
348 | 348 | 'placeholder' => wpinv_format_amount(0), |
349 | 349 | 'value' => wpinv_format_amount(0), |
350 | 350 | 'minimum' => wpinv_format_amount(0), |
351 | - 'label' => __( 'Enter Amount', 'invoicing' ), |
|
351 | + 'label' => __('Enter Amount', 'invoicing'), |
|
352 | 352 | 'description' => '', |
353 | 353 | ) |
354 | 354 | ), |
355 | 355 | |
356 | 356 | array( |
357 | 357 | 'type' => 'price_select', |
358 | - 'name' => __( 'Price Select', 'invoicing' ), |
|
358 | + 'name' => __('Price Select', 'invoicing'), |
|
359 | 359 | 'defaults' => array( |
360 | 360 | 'description' => '', |
361 | - 'label' => __( 'Select Amount', 'invoicing' ), |
|
361 | + 'label' => __('Select Amount', 'invoicing'), |
|
362 | 362 | 'options' => 'Option 1|10, Option 2|20', |
363 | 363 | 'placeholder' => '', |
364 | 364 | 'select_type' => 'select', |
@@ -367,39 +367,39 @@ discard block |
||
367 | 367 | |
368 | 368 | array( |
369 | 369 | 'type' => 'pay_button', |
370 | - 'name' => __( 'Payment Button', 'invoicing' ), |
|
370 | + 'name' => __('Payment Button', 'invoicing'), |
|
371 | 371 | 'defaults' => array( |
372 | 372 | 'value' => '', |
373 | 373 | 'class' => 'btn-primary', |
374 | - 'label' => __( 'Pay %price% »', 'invoicing' ), |
|
375 | - 'free' => __( 'Continue »', 'invoicing' ), |
|
376 | - 'description' => __( 'By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' ), |
|
374 | + 'label' => __('Pay %price% »', 'invoicing'), |
|
375 | + 'free' => __('Continue »', 'invoicing'), |
|
376 | + 'description' => __('By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing'), |
|
377 | 377 | 'premade' => true, |
378 | 378 | ) |
379 | 379 | ), |
380 | 380 | |
381 | 381 | array( |
382 | 382 | 'type' => 'gateway_select', |
383 | - 'name' => __( 'Gateway Select', 'invoicing' ), |
|
383 | + 'name' => __('Gateway Select', 'invoicing'), |
|
384 | 384 | 'defaults' => array( |
385 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
385 | + 'text' => __('Select Payment Method', 'invoicing'), |
|
386 | 386 | 'premade' => true, |
387 | 387 | ) |
388 | 388 | ), |
389 | 389 | |
390 | 390 | array( |
391 | 391 | 'type' => 'total_payable', |
392 | - 'name' => __( 'Total Payable', 'invoicing' ), |
|
392 | + 'name' => __('Total Payable', 'invoicing'), |
|
393 | 393 | 'defaults' => array( |
394 | - 'text' => __( 'Total to pay:', 'invoicing' ), |
|
394 | + 'text' => __('Total to pay:', 'invoicing'), |
|
395 | 395 | ) |
396 | 396 | ), |
397 | 397 | |
398 | 398 | array( |
399 | 399 | 'type' => 'ip_address', |
400 | - 'name' => __( 'IP Address', 'invoicing' ), |
|
400 | + 'name' => __('IP Address', 'invoicing'), |
|
401 | 401 | 'defaults' => array( |
402 | - 'text' => __( 'Your IP address is:', 'invoicing' ), |
|
402 | + 'text' => __('Your IP address is:', 'invoicing'), |
|
403 | 403 | ) |
404 | 404 | ) |
405 | 405 | ); |
@@ -12,179 +12,179 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Checkout { |
14 | 14 | |
15 | - /** |
|
16 | - * @var GetPaid_Payment_Form_Submission |
|
17 | - */ |
|
18 | - protected $payment_form_submission; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - * @param GetPaid_Payment_Form_Submission $submission |
|
24 | - */ |
|
25 | - public function __construct( $submission ) { |
|
26 | - $this->payment_form_submission = $submission; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Processes the checkout. |
|
31 | - * |
|
32 | - */ |
|
33 | - public function process_checkout() { |
|
34 | - |
|
35 | - // Validate the submission. |
|
36 | - $this->validate_submission(); |
|
37 | - |
|
38 | - // Prepare the invoice. |
|
39 | - $items = $this->get_submission_items(); |
|
40 | - $invoice = $this->get_submission_invoice(); |
|
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | - $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | - |
|
44 | - $this->prepare_billing_info( $invoice ); |
|
45 | - |
|
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | - |
|
48 | - // Save the invoice. |
|
49 | - $invoice->set_is_viewed( true ); |
|
50 | - $invoice->recalculate_total(); |
|
15 | + /** |
|
16 | + * @var GetPaid_Payment_Form_Submission |
|
17 | + */ |
|
18 | + protected $payment_form_submission; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + * @param GetPaid_Payment_Form_Submission $submission |
|
24 | + */ |
|
25 | + public function __construct( $submission ) { |
|
26 | + $this->payment_form_submission = $submission; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Processes the checkout. |
|
31 | + * |
|
32 | + */ |
|
33 | + public function process_checkout() { |
|
34 | + |
|
35 | + // Validate the submission. |
|
36 | + $this->validate_submission(); |
|
37 | + |
|
38 | + // Prepare the invoice. |
|
39 | + $items = $this->get_submission_items(); |
|
40 | + $invoice = $this->get_submission_invoice(); |
|
41 | + $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | + $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | + |
|
44 | + $this->prepare_billing_info( $invoice ); |
|
45 | + |
|
46 | + $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | + |
|
48 | + // Save the invoice. |
|
49 | + $invoice->set_is_viewed( true ); |
|
50 | + $invoice->recalculate_total(); |
|
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
54 | 54 | |
55 | - // Send to the gateway. |
|
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | - } |
|
55 | + // Send to the gateway. |
|
56 | + $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Validates the submission. |
|
61 | - * |
|
62 | - */ |
|
63 | - protected function validate_submission() { |
|
59 | + /** |
|
60 | + * Validates the submission. |
|
61 | + * |
|
62 | + */ |
|
63 | + protected function validate_submission() { |
|
64 | 64 | |
65 | - $submission = $this->payment_form_submission; |
|
66 | - $data = $submission->get_data(); |
|
65 | + $submission = $this->payment_form_submission; |
|
66 | + $data = $submission->get_data(); |
|
67 | 67 | |
68 | - // Do we have an error? |
|
68 | + // Do we have an error? |
|
69 | 69 | if ( ! empty( $submission->last_error ) ) { |
70 | - wp_send_json_error( $submission->last_error ); |
|
70 | + wp_send_json_error( $submission->last_error ); |
|
71 | 71 | } |
72 | 72 | |
73 | - // We need a billing email. |
|
73 | + // We need a billing email. |
|
74 | 74 | if ( ! $submission->has_billing_email() ) { |
75 | 75 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | - } |
|
78 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | + } |
|
82 | 82 | |
83 | - // Ensure the gateway is active. |
|
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | - } |
|
83 | + // Ensure the gateway is active. |
|
84 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | + wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | + } |
|
87 | 87 | |
88 | - // Clear any existing errors. |
|
89 | - wpinv_clear_errors(); |
|
88 | + // Clear any existing errors. |
|
89 | + wpinv_clear_errors(); |
|
90 | 90 | |
91 | - // Allow themes and plugins to hook to errors |
|
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
91 | + // Allow themes and plugins to hook to errors |
|
92 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
93 | 93 | |
94 | - // Do we have any errors? |
|
94 | + // Do we have any errors? |
|
95 | 95 | if ( wpinv_get_errors() ) { |
96 | 96 | wp_send_json_error( getpaid_get_errors_html() ); |
97 | - } |
|
97 | + } |
|
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Retrieves submission items. |
|
103 | - * |
|
104 | - * @return GetPaid_Form_Item[] |
|
105 | - */ |
|
106 | - protected function get_submission_items() { |
|
101 | + /** |
|
102 | + * Retrieves submission items. |
|
103 | + * |
|
104 | + * @return GetPaid_Form_Item[] |
|
105 | + */ |
|
106 | + protected function get_submission_items() { |
|
107 | 107 | |
108 | - $items = $this->payment_form_submission->get_items(); |
|
108 | + $items = $this->payment_form_submission->get_items(); |
|
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | 111 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
112 | 112 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
113 | - } |
|
114 | - |
|
115 | - return $items; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Retrieves submission invoice. |
|
120 | - * |
|
121 | - * @return WPInv_Invoice |
|
122 | - */ |
|
123 | - protected function get_submission_invoice() { |
|
124 | - $submission = $this->payment_form_submission; |
|
125 | - |
|
126 | - if ( ! $submission->has_invoice() ) { |
|
127 | - $invoice = new WPInv_Invoice(); |
|
128 | - $invoice->set_created_via( 'payment_form' ); |
|
129 | - return $invoice; |
|
130 | 113 | } |
131 | 114 | |
132 | - $invoice = $submission->get_invoice(); |
|
115 | + return $items; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Retrieves submission invoice. |
|
120 | + * |
|
121 | + * @return WPInv_Invoice |
|
122 | + */ |
|
123 | + protected function get_submission_invoice() { |
|
124 | + $submission = $this->payment_form_submission; |
|
125 | + |
|
126 | + if ( ! $submission->has_invoice() ) { |
|
127 | + $invoice = new WPInv_Invoice(); |
|
128 | + $invoice->set_created_via( 'payment_form' ); |
|
129 | + return $invoice; |
|
130 | + } |
|
131 | + |
|
132 | + $invoice = $submission->get_invoice(); |
|
133 | 133 | |
134 | - // Make sure that it is neither paid or refunded. |
|
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | - } |
|
134 | + // Make sure that it is neither paid or refunded. |
|
135 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | + } |
|
138 | 138 | |
139 | - return $invoice; |
|
140 | - } |
|
139 | + return $invoice; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Processes the submission invoice. |
|
144 | - * |
|
145 | - * @param WPInv_Invoice $invoice |
|
146 | - * @param GetPaid_Form_Item[] $items |
|
147 | - * @return WPInv_Invoice |
|
148 | - */ |
|
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
142 | + /** |
|
143 | + * Processes the submission invoice. |
|
144 | + * |
|
145 | + * @param WPInv_Invoice $invoice |
|
146 | + * @param GetPaid_Form_Item[] $items |
|
147 | + * @return WPInv_Invoice |
|
148 | + */ |
|
149 | + protected function process_submission_invoice( $invoice, $items ) { |
|
150 | 150 | |
151 | - $submission = $this->payment_form_submission; |
|
151 | + $submission = $this->payment_form_submission; |
|
152 | 152 | |
153 | - // Set-up the invoice details. |
|
154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
153 | + // Set-up the invoice details. |
|
154 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
157 | 157 | $invoice->set_items( $items ); |
158 | 158 | $invoice->set_fees( $submission->get_fees() ); |
159 | 159 | $invoice->set_taxes( $submission->get_taxes() ); |
160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | - $invoice->set_gateway( $submission->get_field('wpi-gateway') ); |
|
160 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | + $invoice->set_gateway( $submission->get_field('wpi-gateway') ); |
|
162 | 162 | |
163 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
164 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
163 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
164 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
165 | 165 | |
166 | - if ( $submission->has_discount_code() ) { |
|
166 | + if ( $submission->has_discount_code() ) { |
|
167 | 167 | $invoice->set_discount_code( $submission->get_discount_code() ); |
168 | - } |
|
169 | - |
|
170 | - getpaid_maybe_add_default_address( $invoice ); |
|
171 | - return $invoice; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Retrieves the submission's customer. |
|
176 | - * |
|
177 | - * @return int The customer id. |
|
178 | - */ |
|
179 | - protected function get_submission_customer() { |
|
180 | - $submission = $this->payment_form_submission; |
|
181 | - |
|
182 | - // If this is an existing invoice... |
|
183 | - if ( $submission->has_invoice() ) { |
|
184 | - return $submission->get_invoice()->get_user_id(); |
|
185 | - } |
|
186 | - |
|
187 | - // (Maybe) create the user. |
|
168 | + } |
|
169 | + |
|
170 | + getpaid_maybe_add_default_address( $invoice ); |
|
171 | + return $invoice; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Retrieves the submission's customer. |
|
176 | + * |
|
177 | + * @return int The customer id. |
|
178 | + */ |
|
179 | + protected function get_submission_customer() { |
|
180 | + $submission = $this->payment_form_submission; |
|
181 | + |
|
182 | + // If this is an existing invoice... |
|
183 | + if ( $submission->has_invoice() ) { |
|
184 | + return $submission->get_invoice()->get_user_id(); |
|
185 | + } |
|
186 | + |
|
187 | + // (Maybe) create the user. |
|
188 | 188 | $user = get_current_user_id(); |
189 | 189 | |
190 | 190 | if ( empty( $user ) ) { |
@@ -194,11 +194,11 @@ discard block |
||
194 | 194 | if ( empty( $user ) ) { |
195 | 195 | $user = wpinv_create_user( $submission->get_billing_email() ); |
196 | 196 | |
197 | - // (Maybe) send new user notification. |
|
198 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
199 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
200 | - wp_send_new_user_notifications( $user, 'user' ); |
|
201 | - } |
|
197 | + // (Maybe) send new user notification. |
|
198 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
199 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
200 | + wp_send_new_user_notifications( $user, 'user' ); |
|
201 | + } |
|
202 | 202 | |
203 | 203 | } |
204 | 204 | |
@@ -208,34 +208,34 @@ discard block |
||
208 | 208 | |
209 | 209 | if ( is_numeric( $user ) ) { |
210 | 210 | return $user; |
211 | - } |
|
211 | + } |
|
212 | 212 | |
213 | - return $user->ID; |
|
213 | + return $user->ID; |
|
214 | 214 | |
215 | - } |
|
215 | + } |
|
216 | 216 | |
217 | - /** |
|
217 | + /** |
|
218 | 218 | * Prepares submission data for saving to the database. |
219 | 219 | * |
220 | - * @return array |
|
220 | + * @return array |
|
221 | 221 | */ |
222 | 222 | public function prepare_submission_data_for_saving() { |
223 | 223 | |
224 | - $submission = $this->payment_form_submission; |
|
224 | + $submission = $this->payment_form_submission; |
|
225 | 225 | |
226 | - // Prepared submission details. |
|
226 | + // Prepared submission details. |
|
227 | 227 | $prepared = array( |
228 | - 'all' => array(), |
|
229 | - 'meta' => array(), |
|
230 | - ); |
|
228 | + 'all' => array(), |
|
229 | + 'meta' => array(), |
|
230 | + ); |
|
231 | 231 | |
232 | 232 | // Raw submission details. |
233 | - $data = $submission->get_data(); |
|
233 | + $data = $submission->get_data(); |
|
234 | 234 | |
235 | - // Loop through the submitted details. |
|
235 | + // Loop through the submitted details. |
|
236 | 236 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
237 | 237 | |
238 | - // Skip premade fields. |
|
238 | + // Skip premade fields. |
|
239 | 239 | if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) { |
240 | 240 | continue; |
241 | 241 | } |
@@ -248,11 +248,11 @@ discard block |
||
248 | 248 | // Handle misc fields. |
249 | 249 | if ( isset( $data[ $field['id'] ] ) ) { |
250 | 250 | |
251 | - if ( $field['type'] == 'checkbox' ) { |
|
252 | - $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
253 | - } else { |
|
254 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
255 | - } |
|
251 | + if ( $field['type'] == 'checkbox' ) { |
|
252 | + $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
253 | + } else { |
|
254 | + $value = wp_kses_post( $data[ $field['id'] ] ); |
|
255 | + } |
|
256 | 256 | |
257 | 257 | $label = $field['id']; |
258 | 258 | |
@@ -260,189 +260,189 @@ discard block |
||
260 | 260 | $label = $field['label']; |
261 | 261 | } |
262 | 262 | |
263 | - if ( ! empty( $field['add_meta'] ) ) { |
|
264 | - $prepared['meta'][ wpinv_clean( $label ) ] = $value; |
|
265 | - } |
|
266 | - $prepared['all'][ wpinv_clean( $label ) ] = $value; |
|
263 | + if ( ! empty( $field['add_meta'] ) ) { |
|
264 | + $prepared['meta'][ wpinv_clean( $label ) ] = $value; |
|
265 | + } |
|
266 | + $prepared['all'][ wpinv_clean( $label ) ] = $value; |
|
267 | 267 | |
268 | 268 | } |
269 | 269 | |
270 | - } |
|
270 | + } |
|
271 | 271 | |
272 | - return $prepared; |
|
272 | + return $prepared; |
|
273 | 273 | |
274 | - } |
|
274 | + } |
|
275 | 275 | |
276 | - /** |
|
276 | + /** |
|
277 | 277 | * Retrieves address details. |
278 | 278 | * |
279 | - * @return array |
|
280 | - * @param WPInv_Invoice $invoice |
|
281 | - * @param string $type |
|
279 | + * @return array |
|
280 | + * @param WPInv_Invoice $invoice |
|
281 | + * @param string $type |
|
282 | 282 | */ |
283 | 283 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
284 | 284 | |
285 | - $data = $this->payment_form_submission->get_data(); |
|
286 | - $type = sanitize_key( $type ); |
|
287 | - $address = array(); |
|
288 | - $prepared = array(); |
|
285 | + $data = $this->payment_form_submission->get_data(); |
|
286 | + $type = sanitize_key( $type ); |
|
287 | + $address = array(); |
|
288 | + $prepared = array(); |
|
289 | 289 | |
290 | - if ( ! empty( $data[ $type ] ) ) { |
|
291 | - $address = $data[ $type ]; |
|
292 | - } |
|
290 | + if ( ! empty( $data[ $type ] ) ) { |
|
291 | + $address = $data[ $type ]; |
|
292 | + } |
|
293 | 293 | |
294 | - // Clean address details. |
|
295 | - foreach ( $address as $key => $value ) { |
|
296 | - $key = sanitize_key( $key ); |
|
297 | - $key = str_replace( 'wpinv_', '', $key ); |
|
298 | - $value = wpinv_clean( $value ); |
|
299 | - $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
300 | - } |
|
294 | + // Clean address details. |
|
295 | + foreach ( $address as $key => $value ) { |
|
296 | + $key = sanitize_key( $key ); |
|
297 | + $key = str_replace( 'wpinv_', '', $key ); |
|
298 | + $value = wpinv_clean( $value ); |
|
299 | + $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
300 | + } |
|
301 | 301 | |
302 | - // Filter address details. |
|
303 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
302 | + // Filter address details. |
|
303 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
304 | 304 | |
305 | - // Remove non-whitelisted values. |
|
306 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
305 | + // Remove non-whitelisted values. |
|
306 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
307 | 307 | |
308 | - } |
|
308 | + } |
|
309 | 309 | |
310 | - /** |
|
310 | + /** |
|
311 | 311 | * Prepares the billing details. |
312 | 312 | * |
313 | - * @return array |
|
314 | - * @param WPInv_Invoice $invoice |
|
313 | + * @return array |
|
314 | + * @param WPInv_Invoice $invoice |
|
315 | 315 | */ |
316 | 316 | protected function prepare_billing_info( &$invoice ) { |
317 | 317 | |
318 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
318 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
319 | 319 | |
320 | - // Update the invoice with the billing details. |
|
321 | - $invoice->set_props( $billing_address ); |
|
320 | + // Update the invoice with the billing details. |
|
321 | + $invoice->set_props( $billing_address ); |
|
322 | 322 | |
323 | - } |
|
323 | + } |
|
324 | 324 | |
325 | - /** |
|
325 | + /** |
|
326 | 326 | * Prepares the shipping details. |
327 | 327 | * |
328 | - * @return array |
|
329 | - * @param WPInv_Invoice $invoice |
|
328 | + * @return array |
|
329 | + * @param WPInv_Invoice $invoice |
|
330 | 330 | */ |
331 | 331 | protected function prepare_shipping_info( $invoice ) { |
332 | 332 | |
333 | - $data = $this->payment_form_submission->get_data(); |
|
333 | + $data = $this->payment_form_submission->get_data(); |
|
334 | 334 | |
335 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
336 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
337 | - } |
|
335 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
336 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
337 | + } |
|
338 | 338 | |
339 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
339 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
340 | 340 | |
341 | - } |
|
341 | + } |
|
342 | 342 | |
343 | - /** |
|
344 | - * Confirms the submission is valid and send users to the gateway. |
|
345 | - * |
|
346 | - * @param WPInv_Invoice $invoice |
|
347 | - * @param array $prepared_payment_form_data |
|
348 | - * @param array $shipping |
|
349 | - */ |
|
350 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
343 | + /** |
|
344 | + * Confirms the submission is valid and send users to the gateway. |
|
345 | + * |
|
346 | + * @param WPInv_Invoice $invoice |
|
347 | + * @param array $prepared_payment_form_data |
|
348 | + * @param array $shipping |
|
349 | + */ |
|
350 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
351 | 351 | |
352 | - // Ensure the invoice exists. |
|
352 | + // Ensure the invoice exists. |
|
353 | 353 | if ( ! $invoice->exists() ) { |
354 | 354 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
355 | 355 | } |
356 | 356 | |
357 | - // Save payment form data. |
|
358 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
357 | + // Save payment form data. |
|
358 | + $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
359 | 359 | delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
360 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
361 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
360 | + delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
361 | + if ( ! empty( $prepared_payment_form_data ) ) { |
|
362 | 362 | |
363 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
364 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
365 | - } |
|
363 | + if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
364 | + update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
365 | + } |
|
366 | 366 | |
367 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
368 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
369 | - } |
|
367 | + if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
368 | + update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
369 | + } |
|
370 | 370 | |
371 | - } |
|
371 | + } |
|
372 | 372 | |
373 | - // Save payment form data. |
|
373 | + // Save payment form data. |
|
374 | 374 | if ( ! empty( $shipping ) ) { |
375 | 375 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
376 | - } |
|
376 | + } |
|
377 | 377 | |
378 | - // Backwards compatibility. |
|
378 | + // Backwards compatibility. |
|
379 | 379 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
380 | 380 | |
381 | - $this->process_payment( $invoice ); |
|
381 | + $this->process_payment( $invoice ); |
|
382 | 382 | |
383 | 383 | // If we are here, there was an error. |
384 | - wpinv_send_back_to_checkout( $invoice ); |
|
384 | + wpinv_send_back_to_checkout( $invoice ); |
|
385 | 385 | |
386 | - } |
|
386 | + } |
|
387 | 387 | |
388 | - /** |
|
389 | - * Processes the actual payment. |
|
390 | - * |
|
391 | - * @param WPInv_Invoice $invoice |
|
392 | - */ |
|
393 | - protected function process_payment( $invoice ) { |
|
388 | + /** |
|
389 | + * Processes the actual payment. |
|
390 | + * |
|
391 | + * @param WPInv_Invoice $invoice |
|
392 | + */ |
|
393 | + protected function process_payment( $invoice ) { |
|
394 | 394 | |
395 | - // Clear any checkout errors. |
|
396 | - wpinv_clear_errors(); |
|
395 | + // Clear any checkout errors. |
|
396 | + wpinv_clear_errors(); |
|
397 | 397 | |
398 | - // No need to send free invoices to the gateway. |
|
399 | - if ( $invoice->is_free() ) { |
|
400 | - $this->process_free_payment( $invoice ); |
|
401 | - } |
|
398 | + // No need to send free invoices to the gateway. |
|
399 | + if ( $invoice->is_free() ) { |
|
400 | + $this->process_free_payment( $invoice ); |
|
401 | + } |
|
402 | 402 | |
403 | - $submission = $this->payment_form_submission; |
|
403 | + $submission = $this->payment_form_submission; |
|
404 | 404 | |
405 | - // Fires before sending to the gateway. |
|
406 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
405 | + // Fires before sending to the gateway. |
|
406 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
407 | 407 | |
408 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
409 | - $submission_data = $submission->get_data(); |
|
410 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
411 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
408 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
409 | + $submission_data = $submission->get_data(); |
|
410 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
411 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
412 | 412 | |
413 | - // Validate the currency. |
|
414 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
415 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
416 | - } |
|
413 | + // Validate the currency. |
|
414 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
415 | + wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
416 | + } |
|
417 | 417 | |
418 | - // Check to see if we have any errors. |
|
419 | - if ( wpinv_get_errors() ) { |
|
420 | - wpinv_send_back_to_checkout( $invoice ); |
|
421 | - } |
|
418 | + // Check to see if we have any errors. |
|
419 | + if ( wpinv_get_errors() ) { |
|
420 | + wpinv_send_back_to_checkout( $invoice ); |
|
421 | + } |
|
422 | 422 | |
423 | - // Send info to the gateway for payment processing |
|
424 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
423 | + // Send info to the gateway for payment processing |
|
424 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
425 | 425 | |
426 | - // Backwards compatibility. |
|
427 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
426 | + // Backwards compatibility. |
|
427 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
428 | 428 | |
429 | - } |
|
429 | + } |
|
430 | 430 | |
431 | - /** |
|
432 | - * Marks the invoice as paid in case the checkout is free. |
|
433 | - * |
|
434 | - * @param WPInv_Invoice $invoice |
|
435 | - */ |
|
436 | - protected function process_free_payment( $invoice ) { |
|
431 | + /** |
|
432 | + * Marks the invoice as paid in case the checkout is free. |
|
433 | + * |
|
434 | + * @param WPInv_Invoice $invoice |
|
435 | + */ |
|
436 | + protected function process_free_payment( $invoice ) { |
|
437 | 437 | |
438 | - $invoice->set_gateway( 'none' ); |
|
439 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
440 | - $invoice->mark_paid(); |
|
441 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
438 | + $invoice->set_gateway( 'none' ); |
|
439 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
440 | + $invoice->mark_paid(); |
|
441 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
442 | 442 | |
443 | - } |
|
443 | + } |
|
444 | 444 | |
445 | - /** |
|
445 | + /** |
|
446 | 446 | * Sends a redrect response to payment details. |
447 | 447 | * |
448 | 448 | */ |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Main Checkout Class. |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @param GetPaid_Payment_Form_Submission $submission |
24 | 24 | */ |
25 | - public function __construct( $submission ) { |
|
25 | + public function __construct($submission) { |
|
26 | 26 | $this->payment_form_submission = $submission; |
27 | 27 | } |
28 | 28 | |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | // Prepare the invoice. |
39 | 39 | $items = $this->get_submission_items(); |
40 | 40 | $invoice = $this->get_submission_invoice(); |
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
41 | + $invoice = $this->process_submission_invoice($invoice, $items); |
|
42 | 42 | $prepared = $this->prepare_submission_data_for_saving(); |
43 | 43 | |
44 | - $this->prepare_billing_info( $invoice ); |
|
44 | + $this->prepare_billing_info($invoice); |
|
45 | 45 | |
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
46 | + $shipping = $this->prepare_shipping_info($invoice); |
|
47 | 47 | |
48 | 48 | // Save the invoice. |
49 | - $invoice->set_is_viewed( true ); |
|
49 | + $invoice->set_is_viewed(true); |
|
50 | 50 | $invoice->recalculate_total(); |
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action('getpaid_checkout_invoice_updated', $invoice); |
|
54 | 54 | |
55 | 55 | // Send to the gateway. |
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
56 | + $this->post_process_submission($invoice, $prepared, $shipping); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -66,34 +66,34 @@ discard block |
||
66 | 66 | $data = $submission->get_data(); |
67 | 67 | |
68 | 68 | // Do we have an error? |
69 | - if ( ! empty( $submission->last_error ) ) { |
|
70 | - wp_send_json_error( $submission->last_error ); |
|
69 | + if (!empty($submission->last_error)) { |
|
70 | + wp_send_json_error($submission->last_error); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // We need a billing email. |
74 | - if ( ! $submission->has_billing_email() ) { |
|
75 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
74 | + if (!$submission->has_billing_email()) { |
|
75 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Non-recurring gateways should not be allowed to process recurring invoices. |
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
79 | + if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) { |
|
80 | + wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing')); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | // Ensure the gateway is active. |
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
84 | + if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) { |
|
85 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing')); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Clear any existing errors. |
89 | 89 | wpinv_clear_errors(); |
90 | 90 | |
91 | 91 | // Allow themes and plugins to hook to errors |
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
92 | + do_action('getpaid_checkout_error_checks', $submission); |
|
93 | 93 | |
94 | 94 | // Do we have any errors? |
95 | - if ( wpinv_get_errors() ) { |
|
96 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
95 | + if (wpinv_get_errors()) { |
|
96 | + wp_send_json_error(getpaid_get_errors_html()); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | $items = $this->payment_form_submission->get_items(); |
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | - if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
|
112 | - wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
|
111 | + if (empty($items) && !$this->payment_form_submission->has_fees()) { |
|
112 | + wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing')); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | return $items; |
@@ -123,17 +123,17 @@ discard block |
||
123 | 123 | protected function get_submission_invoice() { |
124 | 124 | $submission = $this->payment_form_submission; |
125 | 125 | |
126 | - if ( ! $submission->has_invoice() ) { |
|
126 | + if (!$submission->has_invoice()) { |
|
127 | 127 | $invoice = new WPInv_Invoice(); |
128 | - $invoice->set_created_via( 'payment_form' ); |
|
128 | + $invoice->set_created_via('payment_form'); |
|
129 | 129 | return $invoice; |
130 | 130 | } |
131 | 131 | |
132 | 132 | $invoice = $submission->get_invoice(); |
133 | 133 | |
134 | 134 | // Make sure that it is neither paid or refunded. |
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
135 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
136 | + wp_send_json_error(__('This invoice has already been paid for.', 'invoicing')); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $invoice; |
@@ -146,28 +146,28 @@ discard block |
||
146 | 146 | * @param GetPaid_Form_Item[] $items |
147 | 147 | * @return WPInv_Invoice |
148 | 148 | */ |
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
149 | + protected function process_submission_invoice($invoice, $items) { |
|
150 | 150 | |
151 | 151 | $submission = $this->payment_form_submission; |
152 | 152 | |
153 | 153 | // Set-up the invoice details. |
154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
157 | - $invoice->set_items( $items ); |
|
158 | - $invoice->set_fees( $submission->get_fees() ); |
|
159 | - $invoice->set_taxes( $submission->get_taxes() ); |
|
160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | - $invoice->set_gateway( $submission->get_field('wpi-gateway') ); |
|
162 | - |
|
163 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
164 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
165 | - |
|
166 | - if ( $submission->has_discount_code() ) { |
|
167 | - $invoice->set_discount_code( $submission->get_discount_code() ); |
|
154 | + $invoice->set_email(sanitize_email($submission->get_billing_email())); |
|
155 | + $invoice->set_user_id($this->get_submission_customer()); |
|
156 | + $invoice->set_payment_form(absint($submission->get_payment_form()->get_id())); |
|
157 | + $invoice->set_items($items); |
|
158 | + $invoice->set_fees($submission->get_fees()); |
|
159 | + $invoice->set_taxes($submission->get_taxes()); |
|
160 | + $invoice->set_discounts($submission->get_discounts()); |
|
161 | + $invoice->set_gateway($submission->get_field('wpi-gateway')); |
|
162 | + |
|
163 | + $address_confirmed = $submission->get_field('confirm-address'); |
|
164 | + $invoice->set_address_confirmed(!empty($address_confirmed)); |
|
165 | + |
|
166 | + if ($submission->has_discount_code()) { |
|
167 | + $invoice->set_discount_code($submission->get_discount_code()); |
|
168 | 168 | } |
169 | 169 | |
170 | - getpaid_maybe_add_default_address( $invoice ); |
|
170 | + getpaid_maybe_add_default_address($invoice); |
|
171 | 171 | return $invoice; |
172 | 172 | } |
173 | 173 | |
@@ -180,33 +180,33 @@ discard block |
||
180 | 180 | $submission = $this->payment_form_submission; |
181 | 181 | |
182 | 182 | // If this is an existing invoice... |
183 | - if ( $submission->has_invoice() ) { |
|
183 | + if ($submission->has_invoice()) { |
|
184 | 184 | return $submission->get_invoice()->get_user_id(); |
185 | 185 | } |
186 | 186 | |
187 | 187 | // (Maybe) create the user. |
188 | 188 | $user = get_current_user_id(); |
189 | 189 | |
190 | - if ( empty( $user ) ) { |
|
191 | - $user = get_user_by( 'email', $submission->get_billing_email() ); |
|
190 | + if (empty($user)) { |
|
191 | + $user = get_user_by('email', $submission->get_billing_email()); |
|
192 | 192 | } |
193 | 193 | |
194 | - if ( empty( $user ) ) { |
|
195 | - $user = wpinv_create_user( $submission->get_billing_email() ); |
|
194 | + if (empty($user)) { |
|
195 | + $user = wpinv_create_user($submission->get_billing_email()); |
|
196 | 196 | |
197 | 197 | // (Maybe) send new user notification. |
198 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
199 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
200 | - wp_send_new_user_notifications( $user, 'user' ); |
|
198 | + $should_send_notification = wpinv_get_option('disable_new_user_emails'); |
|
199 | + if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) { |
|
200 | + wp_send_new_user_notifications($user, 'user'); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | } |
204 | 204 | |
205 | - if ( is_wp_error( $user ) ) { |
|
206 | - wp_send_json_error( $user->get_error_message() ); |
|
205 | + if (is_wp_error($user)) { |
|
206 | + wp_send_json_error($user->get_error_message()); |
|
207 | 207 | } |
208 | 208 | |
209 | - if ( is_numeric( $user ) ) { |
|
209 | + if (is_numeric($user)) { |
|
210 | 210 | return $user; |
211 | 211 | } |
212 | 212 | |
@@ -230,40 +230,40 @@ discard block |
||
230 | 230 | ); |
231 | 231 | |
232 | 232 | // Raw submission details. |
233 | - $data = $submission->get_data(); |
|
233 | + $data = $submission->get_data(); |
|
234 | 234 | |
235 | 235 | // Loop through the submitted details. |
236 | - foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
|
236 | + foreach ($submission->get_payment_form()->get_elements() as $field) { |
|
237 | 237 | |
238 | 238 | // Skip premade fields. |
239 | - if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) { |
|
239 | + if (!empty($field['premade']) || $field['type'] == 'address') { |
|
240 | 240 | continue; |
241 | 241 | } |
242 | 242 | |
243 | 243 | // If it is required and not set, abort. |
244 | - if ( ! $submission->is_required_field_set( $field ) ) { |
|
245 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
244 | + if (!$submission->is_required_field_set($field)) { |
|
245 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | // Handle misc fields. |
249 | - if ( isset( $data[ $field['id'] ] ) ) { |
|
249 | + if (isset($data[$field['id']])) { |
|
250 | 250 | |
251 | - if ( $field['type'] == 'checkbox' ) { |
|
252 | - $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
251 | + if ($field['type'] == 'checkbox') { |
|
252 | + $value = isset($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing'); |
|
253 | 253 | } else { |
254 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
254 | + $value = wp_kses_post($data[$field['id']]); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | $label = $field['id']; |
258 | 258 | |
259 | - if ( isset( $field['label'] ) ) { |
|
259 | + if (isset($field['label'])) { |
|
260 | 260 | $label = $field['label']; |
261 | 261 | } |
262 | 262 | |
263 | - if ( ! empty( $field['add_meta'] ) ) { |
|
264 | - $prepared['meta'][ wpinv_clean( $label ) ] = $value; |
|
263 | + if (!empty($field['add_meta'])) { |
|
264 | + $prepared['meta'][wpinv_clean($label)] = $value; |
|
265 | 265 | } |
266 | - $prepared['all'][ wpinv_clean( $label ) ] = $value; |
|
266 | + $prepared['all'][wpinv_clean($label)] = $value; |
|
267 | 267 | |
268 | 268 | } |
269 | 269 | |
@@ -280,30 +280,30 @@ discard block |
||
280 | 280 | * @param WPInv_Invoice $invoice |
281 | 281 | * @param string $type |
282 | 282 | */ |
283 | - public function prepare_address_details( $invoice, $type = 'billing' ) { |
|
283 | + public function prepare_address_details($invoice, $type = 'billing') { |
|
284 | 284 | |
285 | 285 | $data = $this->payment_form_submission->get_data(); |
286 | - $type = sanitize_key( $type ); |
|
286 | + $type = sanitize_key($type); |
|
287 | 287 | $address = array(); |
288 | 288 | $prepared = array(); |
289 | 289 | |
290 | - if ( ! empty( $data[ $type ] ) ) { |
|
291 | - $address = $data[ $type ]; |
|
290 | + if (!empty($data[$type])) { |
|
291 | + $address = $data[$type]; |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | // Clean address details. |
295 | - foreach ( $address as $key => $value ) { |
|
296 | - $key = sanitize_key( $key ); |
|
297 | - $key = str_replace( 'wpinv_', '', $key ); |
|
298 | - $value = wpinv_clean( $value ); |
|
299 | - $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
295 | + foreach ($address as $key => $value) { |
|
296 | + $key = sanitize_key($key); |
|
297 | + $key = str_replace('wpinv_', '', $key); |
|
298 | + $value = wpinv_clean($value); |
|
299 | + $prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | // Filter address details. |
303 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
303 | + $prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice); |
|
304 | 304 | |
305 | 305 | // Remove non-whitelisted values. |
306 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
306 | + return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY); |
|
307 | 307 | |
308 | 308 | } |
309 | 309 | |
@@ -313,12 +313,12 @@ discard block |
||
313 | 313 | * @return array |
314 | 314 | * @param WPInv_Invoice $invoice |
315 | 315 | */ |
316 | - protected function prepare_billing_info( &$invoice ) { |
|
316 | + protected function prepare_billing_info(&$invoice) { |
|
317 | 317 | |
318 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
318 | + $billing_address = $this->prepare_address_details($invoice, 'billing'); |
|
319 | 319 | |
320 | 320 | // Update the invoice with the billing details. |
321 | - $invoice->set_props( $billing_address ); |
|
321 | + $invoice->set_props($billing_address); |
|
322 | 322 | |
323 | 323 | } |
324 | 324 | |
@@ -328,15 +328,15 @@ discard block |
||
328 | 328 | * @return array |
329 | 329 | * @param WPInv_Invoice $invoice |
330 | 330 | */ |
331 | - protected function prepare_shipping_info( $invoice ) { |
|
331 | + protected function prepare_shipping_info($invoice) { |
|
332 | 332 | |
333 | 333 | $data = $this->payment_form_submission->get_data(); |
334 | 334 | |
335 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
336 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
335 | + if (empty($data['same-shipping-address'])) { |
|
336 | + return $this->prepare_address_details($invoice, 'shipping'); |
|
337 | 337 | } |
338 | 338 | |
339 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
339 | + return $this->prepare_address_details($invoice, 'billing'); |
|
340 | 340 | |
341 | 341 | } |
342 | 342 | |
@@ -347,41 +347,41 @@ discard block |
||
347 | 347 | * @param array $prepared_payment_form_data |
348 | 348 | * @param array $shipping |
349 | 349 | */ |
350 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
350 | + protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) { |
|
351 | 351 | |
352 | 352 | // Ensure the invoice exists. |
353 | - if ( ! $invoice->exists() ) { |
|
354 | - wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
|
353 | + if (!$invoice->exists()) { |
|
354 | + wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing')); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | // Save payment form data. |
358 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
359 | - delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
|
360 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
361 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
358 | + $prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice); |
|
359 | + delete_post_meta($invoice->get_id(), 'payment_form_data'); |
|
360 | + delete_post_meta($invoice->get_id(), 'additional_meta_data'); |
|
361 | + if (!empty($prepared_payment_form_data)) { |
|
362 | 362 | |
363 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
364 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
363 | + if (!empty($prepared_payment_form_data['all'])) { |
|
364 | + update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']); |
|
365 | 365 | } |
366 | 366 | |
367 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
368 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
367 | + if (!empty($prepared_payment_form_data['meta'])) { |
|
368 | + update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | } |
372 | 372 | |
373 | 373 | // Save payment form data. |
374 | - if ( ! empty( $shipping ) ) { |
|
375 | - update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
|
374 | + if (!empty($shipping)) { |
|
375 | + update_post_meta($invoice->get_id(), 'shipping_address', $shipping); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | // Backwards compatibility. |
379 | - add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
|
379 | + add_filter('wp_redirect', array($this, 'send_redirect_response')); |
|
380 | 380 | |
381 | - $this->process_payment( $invoice ); |
|
381 | + $this->process_payment($invoice); |
|
382 | 382 | |
383 | 383 | // If we are here, there was an error. |
384 | - wpinv_send_back_to_checkout( $invoice ); |
|
384 | + wpinv_send_back_to_checkout($invoice); |
|
385 | 385 | |
386 | 386 | } |
387 | 387 | |
@@ -390,41 +390,41 @@ discard block |
||
390 | 390 | * |
391 | 391 | * @param WPInv_Invoice $invoice |
392 | 392 | */ |
393 | - protected function process_payment( $invoice ) { |
|
393 | + protected function process_payment($invoice) { |
|
394 | 394 | |
395 | 395 | // Clear any checkout errors. |
396 | 396 | wpinv_clear_errors(); |
397 | 397 | |
398 | 398 | // No need to send free invoices to the gateway. |
399 | - if ( $invoice->is_free() ) { |
|
400 | - $this->process_free_payment( $invoice ); |
|
399 | + if ($invoice->is_free()) { |
|
400 | + $this->process_free_payment($invoice); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | $submission = $this->payment_form_submission; |
404 | 404 | |
405 | 405 | // Fires before sending to the gateway. |
406 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
406 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
407 | 407 | |
408 | 408 | // Allow the sumission data to be modified before it is sent to the gateway. |
409 | 409 | $submission_data = $submission->get_data(); |
410 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
411 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
410 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice); |
|
411 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
412 | 412 | |
413 | 413 | // Validate the currency. |
414 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
415 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
414 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
415 | + wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing')); |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | // Check to see if we have any errors. |
419 | - if ( wpinv_get_errors() ) { |
|
420 | - wpinv_send_back_to_checkout( $invoice ); |
|
419 | + if (wpinv_get_errors()) { |
|
420 | + wpinv_send_back_to_checkout($invoice); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | // Send info to the gateway for payment processing |
424 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
424 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
425 | 425 | |
426 | 426 | // Backwards compatibility. |
427 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
427 | + wpinv_send_to_gateway($submission_gateway, $invoice); |
|
428 | 428 | |
429 | 429 | } |
430 | 430 | |
@@ -433,12 +433,12 @@ discard block |
||
433 | 433 | * |
434 | 434 | * @param WPInv_Invoice $invoice |
435 | 435 | */ |
436 | - protected function process_free_payment( $invoice ) { |
|
436 | + protected function process_free_payment($invoice) { |
|
437 | 437 | |
438 | - $invoice->set_gateway( 'none' ); |
|
439 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
438 | + $invoice->set_gateway('none'); |
|
439 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
440 | 440 | $invoice->mark_paid(); |
441 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
441 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
442 | 442 | |
443 | 443 | } |
444 | 444 | |
@@ -446,9 +446,9 @@ discard block |
||
446 | 446 | * Sends a redrect response to payment details. |
447 | 447 | * |
448 | 448 | */ |
449 | - public function send_redirect_response( $url ) { |
|
450 | - $url = urlencode( $url ); |
|
451 | - wp_send_json_success( $url ); |
|
449 | + public function send_redirect_response($url) { |
|
450 | + $url = urlencode($url); |
|
451 | + wp_send_json_success($url); |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | } |
@@ -12,228 +12,228 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Taxes { |
14 | 14 | |
15 | - /** |
|
16 | - * Submission taxes. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $taxes = array(); |
|
20 | - |
|
21 | - /** |
|
22 | - * Whether or not we should skip the taxes. |
|
23 | - * @var bool |
|
24 | - */ |
|
25 | - protected $skip_taxes = false; |
|
15 | + /** |
|
16 | + * Submission taxes. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $taxes = array(); |
|
20 | + |
|
21 | + /** |
|
22 | + * Whether or not we should skip the taxes. |
|
23 | + * @var bool |
|
24 | + */ |
|
25 | + protected $skip_taxes = false; |
|
26 | 26 | |
27 | 27 | /** |
28 | - * Class constructor |
|
29 | - * |
|
30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
31 | - */ |
|
32 | - public function __construct( $submission ) { |
|
33 | - |
|
34 | - // Validate VAT number. |
|
35 | - $this->validate_vat( $submission ); |
|
36 | - |
|
37 | - if ( $this->skip_taxes ) { |
|
38 | - return; |
|
39 | - } |
|
40 | - |
|
41 | - foreach ( $submission->get_items() as $item ) { |
|
42 | - $this->process_item_tax( $item, $submission ); |
|
43 | - } |
|
44 | - |
|
45 | - // Process any existing invoice taxes. |
|
46 | - if ( $submission->has_invoice() ) { |
|
47 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
48 | - } |
|
49 | - |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Maybe process tax. |
|
54 | - * |
|
55 | - * @since 1.0.19 |
|
56 | - * @param GetPaid_Form_Item $item |
|
57 | - * @param GetPaid_Payment_Form_Submission $submission |
|
58 | - */ |
|
59 | - public function process_item_tax( $item, $submission ) { |
|
60 | - |
|
61 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
62 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
63 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
64 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
65 | - |
|
66 | - foreach ( $taxes as $name => $amount ) { |
|
67 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
68 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
69 | - |
|
70 | - $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
71 | - |
|
72 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
73 | - $this->taxes[ $name ] = $tax; |
|
74 | - continue; |
|
75 | - } |
|
76 | - |
|
77 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
78 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
79 | - |
|
80 | - } |
|
81 | - |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Checks if the submission has a digital item. |
|
86 | - * |
|
87 | - * @param GetPaid_Payment_Form_Submission $submission |
|
88 | - * @since 1.0.19 |
|
89 | - * @return bool |
|
90 | - */ |
|
91 | - public function has_digital_item( $submission ) { |
|
92 | - |
|
93 | - foreach ( $submission->get_items() as $item ) { |
|
94 | - |
|
95 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
96 | - return true; |
|
97 | - } |
|
98 | - |
|
99 | - } |
|
100 | - |
|
101 | - return false; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Checks if this is an eu store. |
|
106 | - * |
|
107 | - * @since 1.0.19 |
|
108 | - * @return bool |
|
109 | - */ |
|
110 | - public static function is_eu_store() { |
|
111 | - return self::is_eu_country( wpinv_get_default_country() ); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Checks if this is an eu country. |
|
116 | - * |
|
117 | - * @param string $country |
|
118 | - * @since 1.0.19 |
|
119 | - * @return bool |
|
120 | - */ |
|
121 | - public static function is_eu_country( $country ) { |
|
122 | - return getpaid_is_eu_state( $country ); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Checks if this is an eu purchase. |
|
127 | - * |
|
128 | - * @param string $customer_country |
|
129 | - * @since 1.0.19 |
|
130 | - * @return bool |
|
131 | - */ |
|
132 | - public static function is_eu_transaction( $customer_country ) { |
|
133 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Retrieves the vat number. |
|
138 | - * |
|
139 | - * @param GetPaid_Payment_Form_Submission $submission |
|
140 | - * @since 1.0.19 |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function get_vat_number( $submission ) { |
|
144 | - |
|
145 | - // Retrieve from the posted number. |
|
146 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
147 | - if ( ! is_null( $vat_number ) ) { |
|
148 | - return wpinv_clean( $vat_number ); |
|
149 | - } |
|
150 | - |
|
151 | - return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Retrieves the company. |
|
156 | - * |
|
157 | - * @param GetPaid_Payment_Form_Submission $submission |
|
158 | - * @since 1.0.19 |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function get_company( $submission ) { |
|
162 | - |
|
163 | - // Retrieve from the posted data. |
|
164 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
165 | - if ( ! empty( $company ) ) { |
|
166 | - return wpinv_clean( $company ); |
|
167 | - } |
|
168 | - |
|
169 | - // Retrieve from the invoice. |
|
170 | - return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Checks if we require a VAT number. |
|
175 | - * |
|
176 | - * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
177 | - * @param bool $country_in_eu Whether the customer country is from the EU |
|
178 | - * @since 1.0.19 |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
182 | - |
|
183 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
184 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
185 | - $is_eu = $ip_in_eu || $country_in_eu; |
|
186 | - |
|
187 | - return $prevent_b2c && $is_eu; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Validate VAT data. |
|
192 | - * |
|
193 | - * @param GetPaid_Payment_Form_Submission $submission |
|
194 | - * @since 1.0.19 |
|
195 | - */ |
|
196 | - public function validate_vat( $submission ) { |
|
197 | - |
|
198 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
199 | - |
|
200 | - // Abort if we are not validating vat numbers. |
|
201 | - if ( ! $in_eu ) { |
|
28 | + * Class constructor |
|
29 | + * |
|
30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
31 | + */ |
|
32 | + public function __construct( $submission ) { |
|
33 | + |
|
34 | + // Validate VAT number. |
|
35 | + $this->validate_vat( $submission ); |
|
36 | + |
|
37 | + if ( $this->skip_taxes ) { |
|
202 | 38 | return; |
203 | - } |
|
39 | + } |
|
40 | + |
|
41 | + foreach ( $submission->get_items() as $item ) { |
|
42 | + $this->process_item_tax( $item, $submission ); |
|
43 | + } |
|
44 | + |
|
45 | + // Process any existing invoice taxes. |
|
46 | + if ( $submission->has_invoice() ) { |
|
47 | + $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
48 | + } |
|
49 | + |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Maybe process tax. |
|
54 | + * |
|
55 | + * @since 1.0.19 |
|
56 | + * @param GetPaid_Form_Item $item |
|
57 | + * @param GetPaid_Payment_Form_Submission $submission |
|
58 | + */ |
|
59 | + public function process_item_tax( $item, $submission ) { |
|
60 | + |
|
61 | + $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
62 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
63 | + $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
64 | + $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
65 | + |
|
66 | + foreach ( $taxes as $name => $amount ) { |
|
67 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
68 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
69 | + |
|
70 | + $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
71 | + |
|
72 | + if ( ! isset( $this->taxes[ $name ] ) ) { |
|
73 | + $this->taxes[ $name ] = $tax; |
|
74 | + continue; |
|
75 | + } |
|
76 | + |
|
77 | + $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
78 | + $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
79 | + |
|
80 | + } |
|
81 | + |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Checks if the submission has a digital item. |
|
86 | + * |
|
87 | + * @param GetPaid_Payment_Form_Submission $submission |
|
88 | + * @since 1.0.19 |
|
89 | + * @return bool |
|
90 | + */ |
|
91 | + public function has_digital_item( $submission ) { |
|
92 | + |
|
93 | + foreach ( $submission->get_items() as $item ) { |
|
94 | + |
|
95 | + if ( 'digital' == $item->get_vat_rule() ) { |
|
96 | + return true; |
|
97 | + } |
|
98 | + |
|
99 | + } |
|
204 | 100 | |
205 | - // Prepare variables. |
|
206 | - $vat_number = $this->get_vat_number( $submission ); |
|
207 | - $ip_country = getpaid_get_ip_country(); |
|
101 | + return false; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Checks if this is an eu store. |
|
106 | + * |
|
107 | + * @since 1.0.19 |
|
108 | + * @return bool |
|
109 | + */ |
|
110 | + public static function is_eu_store() { |
|
111 | + return self::is_eu_country( wpinv_get_default_country() ); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Checks if this is an eu country. |
|
116 | + * |
|
117 | + * @param string $country |
|
118 | + * @since 1.0.19 |
|
119 | + * @return bool |
|
120 | + */ |
|
121 | + public static function is_eu_country( $country ) { |
|
122 | + return getpaid_is_eu_state( $country ); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Checks if this is an eu purchase. |
|
127 | + * |
|
128 | + * @param string $customer_country |
|
129 | + * @since 1.0.19 |
|
130 | + * @return bool |
|
131 | + */ |
|
132 | + public static function is_eu_transaction( $customer_country ) { |
|
133 | + return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Retrieves the vat number. |
|
138 | + * |
|
139 | + * @param GetPaid_Payment_Form_Submission $submission |
|
140 | + * @since 1.0.19 |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function get_vat_number( $submission ) { |
|
144 | + |
|
145 | + // Retrieve from the posted number. |
|
146 | + $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
147 | + if ( ! is_null( $vat_number ) ) { |
|
148 | + return wpinv_clean( $vat_number ); |
|
149 | + } |
|
150 | + |
|
151 | + return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Retrieves the company. |
|
156 | + * |
|
157 | + * @param GetPaid_Payment_Form_Submission $submission |
|
158 | + * @since 1.0.19 |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function get_company( $submission ) { |
|
162 | + |
|
163 | + // Retrieve from the posted data. |
|
164 | + $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
165 | + if ( ! empty( $company ) ) { |
|
166 | + return wpinv_clean( $company ); |
|
167 | + } |
|
168 | + |
|
169 | + // Retrieve from the invoice. |
|
170 | + return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Checks if we require a VAT number. |
|
175 | + * |
|
176 | + * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
177 | + * @param bool $country_in_eu Whether the customer country is from the EU |
|
178 | + * @since 1.0.19 |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
182 | + |
|
183 | + $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
184 | + $prevent_b2c = ! empty( $prevent_b2c ); |
|
185 | + $is_eu = $ip_in_eu || $country_in_eu; |
|
186 | + |
|
187 | + return $prevent_b2c && $is_eu; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Validate VAT data. |
|
192 | + * |
|
193 | + * @param GetPaid_Payment_Form_Submission $submission |
|
194 | + * @since 1.0.19 |
|
195 | + */ |
|
196 | + public function validate_vat( $submission ) { |
|
197 | + |
|
198 | + $in_eu = $this->is_eu_transaction( $submission->country ); |
|
199 | + |
|
200 | + // Abort if we are not validating vat numbers. |
|
201 | + if ( ! $in_eu ) { |
|
202 | + return; |
|
203 | + } |
|
204 | + |
|
205 | + // Prepare variables. |
|
206 | + $vat_number = $this->get_vat_number( $submission ); |
|
207 | + $ip_country = getpaid_get_ip_country(); |
|
208 | 208 | $is_eu = $this->is_eu_country( $submission->country ); |
209 | 209 | $is_ip_eu = $this->is_eu_country( $ip_country ); |
210 | 210 | |
211 | - // Maybe abort early for initial fetches. |
|
212 | - if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
213 | - return; |
|
214 | - } |
|
211 | + // Maybe abort early for initial fetches. |
|
212 | + if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
213 | + return; |
|
214 | + } |
|
215 | 215 | |
216 | - // If we're preventing business to consumer purchases, |
|
217 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
216 | + // If we're preventing business to consumer purchases, |
|
217 | + if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
218 | 218 | |
219 | - // Ensure that a vat number has been specified. |
|
220 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) ); |
|
219 | + // Ensure that a vat number has been specified. |
|
220 | + throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) ); |
|
221 | 221 | |
222 | - } |
|
222 | + } |
|
223 | 223 | |
224 | - if ( empty( $vat_number ) ) { |
|
225 | - return; |
|
226 | - } |
|
224 | + if ( empty( $vat_number ) ) { |
|
225 | + return; |
|
226 | + } |
|
227 | 227 | |
228 | - if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
229 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
230 | - } |
|
228 | + if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
229 | + throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
230 | + } |
|
231 | 231 | |
232 | - if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
233 | - return; |
|
234 | - } |
|
232 | + if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
233 | + return; |
|
234 | + } |
|
235 | 235 | |
236 | - $this->skip_taxes = true; |
|
237 | - } |
|
236 | + $this->skip_taxes = true; |
|
237 | + } |
|
238 | 238 | |
239 | 239 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment form submission taxes class |
@@ -29,22 +29,22 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @param GetPaid_Payment_Form_Submission $submission |
31 | 31 | */ |
32 | - public function __construct( $submission ) { |
|
32 | + public function __construct($submission) { |
|
33 | 33 | |
34 | 34 | // Validate VAT number. |
35 | - $this->validate_vat( $submission ); |
|
35 | + $this->validate_vat($submission); |
|
36 | 36 | |
37 | - if ( $this->skip_taxes ) { |
|
37 | + if ($this->skip_taxes) { |
|
38 | 38 | return; |
39 | 39 | } |
40 | 40 | |
41 | - foreach ( $submission->get_items() as $item ) { |
|
42 | - $this->process_item_tax( $item, $submission ); |
|
41 | + foreach ($submission->get_items() as $item) { |
|
42 | + $this->process_item_tax($item, $submission); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | // Process any existing invoice taxes. |
46 | - if ( $submission->has_invoice() ) { |
|
47 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
46 | + if ($submission->has_invoice()) { |
|
47 | + $this->taxes = array_replace($submission->get_invoice()->get_taxes(), $this->taxes); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
@@ -56,26 +56,26 @@ discard block |
||
56 | 56 | * @param GetPaid_Form_Item $item |
57 | 57 | * @param GetPaid_Payment_Form_Submission $submission |
58 | 58 | */ |
59 | - public function process_item_tax( $item, $submission ) { |
|
59 | + public function process_item_tax($item, $submission) { |
|
60 | 60 | |
61 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
62 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
63 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
64 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
61 | + $rates = getpaid_get_item_tax_rates($item, $submission->country, $submission->state); |
|
62 | + $rates = getpaid_filter_item_tax_rates($item, $rates); |
|
63 | + $taxes = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, false), $rates); |
|
64 | + $r_taxes = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, true), $rates); |
|
65 | 65 | |
66 | - foreach ( $taxes as $name => $amount ) { |
|
67 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
68 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
66 | + foreach ($taxes as $name => $amount) { |
|
67 | + $recurring = isset($r_taxes[$name]) ? $r_taxes[$name] : 0; |
|
68 | + $tax = getpaid_prepare_item_tax($item, $name, $amount, $recurring); |
|
69 | 69 | |
70 | - $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
70 | + $item->item_tax += wpinv_sanitize_amount($tax['initial_tax']); |
|
71 | 71 | |
72 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
73 | - $this->taxes[ $name ] = $tax; |
|
72 | + if (!isset($this->taxes[$name])) { |
|
73 | + $this->taxes[$name] = $tax; |
|
74 | 74 | continue; |
75 | 75 | } |
76 | 76 | |
77 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
78 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
77 | + $this->taxes[$name]['initial_tax'] += $tax['initial_tax']; |
|
78 | + $this->taxes[$name]['recurring_tax'] += $tax['recurring_tax']; |
|
79 | 79 | |
80 | 80 | } |
81 | 81 | |
@@ -88,11 +88,11 @@ discard block |
||
88 | 88 | * @since 1.0.19 |
89 | 89 | * @return bool |
90 | 90 | */ |
91 | - public function has_digital_item( $submission ) { |
|
91 | + public function has_digital_item($submission) { |
|
92 | 92 | |
93 | - foreach ( $submission->get_items() as $item ) { |
|
93 | + foreach ($submission->get_items() as $item) { |
|
94 | 94 | |
95 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
95 | + if ('digital' == $item->get_vat_rule()) { |
|
96 | 96 | return true; |
97 | 97 | } |
98 | 98 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @return bool |
109 | 109 | */ |
110 | 110 | public static function is_eu_store() { |
111 | - return self::is_eu_country( wpinv_get_default_country() ); |
|
111 | + return self::is_eu_country(wpinv_get_default_country()); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | * @since 1.0.19 |
119 | 119 | * @return bool |
120 | 120 | */ |
121 | - public static function is_eu_country( $country ) { |
|
122 | - return getpaid_is_eu_state( $country ); |
|
121 | + public static function is_eu_country($country) { |
|
122 | + return getpaid_is_eu_state($country); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | * @since 1.0.19 |
130 | 130 | * @return bool |
131 | 131 | */ |
132 | - public static function is_eu_transaction( $customer_country ) { |
|
133 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
132 | + public static function is_eu_transaction($customer_country) { |
|
133 | + return self::is_eu_country($customer_country) && self::is_eu_store(); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -140,12 +140,12 @@ discard block |
||
140 | 140 | * @since 1.0.19 |
141 | 141 | * @return string |
142 | 142 | */ |
143 | - public function get_vat_number( $submission ) { |
|
143 | + public function get_vat_number($submission) { |
|
144 | 144 | |
145 | 145 | // Retrieve from the posted number. |
146 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
147 | - if ( ! is_null( $vat_number ) ) { |
|
148 | - return wpinv_clean( $vat_number ); |
|
146 | + $vat_number = $submission->get_field('wpinv_vat_number', 'billing'); |
|
147 | + if (!is_null($vat_number)) { |
|
148 | + return wpinv_clean($vat_number); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
@@ -158,12 +158,12 @@ discard block |
||
158 | 158 | * @since 1.0.19 |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - public function get_company( $submission ) { |
|
161 | + public function get_company($submission) { |
|
162 | 162 | |
163 | 163 | // Retrieve from the posted data. |
164 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
165 | - if ( ! empty( $company ) ) { |
|
166 | - return wpinv_clean( $company ); |
|
164 | + $company = $submission->get_field('wpinv_company', 'billing'); |
|
165 | + if (!empty($company)) { |
|
166 | + return wpinv_clean($company); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | // Retrieve from the invoice. |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | * @since 1.0.19 |
179 | 179 | * @return string |
180 | 180 | */ |
181 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
181 | + public function requires_vat($ip_in_eu, $country_in_eu) { |
|
182 | 182 | |
183 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
184 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
183 | + $prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase'); |
|
184 | + $prevent_b2c = !empty($prevent_b2c); |
|
185 | 185 | $is_eu = $ip_in_eu || $country_in_eu; |
186 | 186 | |
187 | 187 | return $prevent_b2c && $is_eu; |
@@ -193,43 +193,43 @@ discard block |
||
193 | 193 | * @param GetPaid_Payment_Form_Submission $submission |
194 | 194 | * @since 1.0.19 |
195 | 195 | */ |
196 | - public function validate_vat( $submission ) { |
|
196 | + public function validate_vat($submission) { |
|
197 | 197 | |
198 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
198 | + $in_eu = $this->is_eu_transaction($submission->country); |
|
199 | 199 | |
200 | 200 | // Abort if we are not validating vat numbers. |
201 | - if ( ! $in_eu ) { |
|
201 | + if (!$in_eu) { |
|
202 | 202 | return; |
203 | 203 | } |
204 | 204 | |
205 | 205 | // Prepare variables. |
206 | - $vat_number = $this->get_vat_number( $submission ); |
|
206 | + $vat_number = $this->get_vat_number($submission); |
|
207 | 207 | $ip_country = getpaid_get_ip_country(); |
208 | - $is_eu = $this->is_eu_country( $submission->country ); |
|
209 | - $is_ip_eu = $this->is_eu_country( $ip_country ); |
|
208 | + $is_eu = $this->is_eu_country($submission->country); |
|
209 | + $is_ip_eu = $this->is_eu_country($ip_country); |
|
210 | 210 | |
211 | 211 | // Maybe abort early for initial fetches. |
212 | - if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
212 | + if ($submission->is_initial_fetch() && empty($vat_number)) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | 216 | // If we're preventing business to consumer purchases, |
217 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
217 | + if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) { |
|
218 | 218 | |
219 | 219 | // Ensure that a vat number has been specified. |
220 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) ); |
|
220 | + throw new GetPaid_Payment_Exception('.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __('Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing')); |
|
221 | 221 | |
222 | 222 | } |
223 | 223 | |
224 | - if ( empty( $vat_number ) ) { |
|
224 | + if (empty($vat_number)) { |
|
225 | 225 | return; |
226 | 226 | } |
227 | 227 | |
228 | - if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
229 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
228 | + if (wpinv_should_validate_vat_number() && !wpinv_validate_vat_number($vat_number, $submission->country)) { |
|
229 | + throw new GetPaid_Payment_Exception('.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __('Your VAT number is invalid', 'invoicing')); |
|
230 | 230 | } |
231 | 231 | |
232 | - if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
232 | + if (wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option('vat_same_country_rule', 'vat_too')) { |
|
233 | 233 | return; |
234 | 234 | } |
235 | 235 |