@@ -70,24 +70,24 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @param array $args |
72 | 72 | */ |
73 | - public function register( $args ) { |
|
73 | + public function register($args) { |
|
74 | 74 | $args_default = array( |
75 | 75 | 'id' => '', |
76 | 76 | 'version' => '', |
77 | 77 | 'callback' => '', |
78 | 78 | ); |
79 | 79 | |
80 | - $args = wp_parse_args( $args, $args_default ); |
|
80 | + $args = wp_parse_args($args, $args_default); |
|
81 | 81 | |
82 | 82 | // You can only register database upgrade. |
83 | 83 | $args['type'] = 'database'; |
84 | 84 | |
85 | 85 | // Bailout. |
86 | - if ( empty( $args['id'] ) || empty( $args['version'] ) || empty( $args['callback'] ) || ! is_callable( $args['callback'] ) ) { |
|
86 | + if (empty($args['id']) || empty($args['version']) || empty($args['callback']) || ! is_callable($args['callback'])) { |
|
87 | 87 | return; |
88 | 88 | } |
89 | 89 | |
90 | - $this->updates[ $args['type'] ][] = $args; |
|
90 | + $this->updates[$args['type']][] = $args; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | |
@@ -102,32 +102,32 @@ discard block |
||
102 | 102 | * |
103 | 103 | * @return array |
104 | 104 | */ |
105 | - public function get_updates( $update_type = '', $status = 'all' ) { |
|
105 | + public function get_updates($update_type = '', $status = 'all') { |
|
106 | 106 | // return all updates. |
107 | - if ( empty( $update_type ) ) { |
|
107 | + if (empty($update_type)) { |
|
108 | 108 | return $this->updates; |
109 | 109 | } |
110 | 110 | |
111 | 111 | // Get specific update. |
112 | - $updates = ! empty( $this->updates[ $update_type ] ) ? $this->updates[ $update_type ] : array(); |
|
112 | + $updates = ! empty($this->updates[$update_type]) ? $this->updates[$update_type] : array(); |
|
113 | 113 | |
114 | 114 | // Bailout. |
115 | - if ( empty( $updates ) ) { |
|
115 | + if (empty($updates)) { |
|
116 | 116 | return $updates; |
117 | 117 | } |
118 | 118 | |
119 | - switch ( $status ) { |
|
119 | + switch ($status) { |
|
120 | 120 | case 'new': |
121 | 121 | // Remove already completed updates. |
122 | 122 | $completed_updates = give_get_completed_upgrades(); |
123 | 123 | |
124 | - if ( ! empty( $completed_updates ) ) { |
|
125 | - foreach ( $updates as $index => $update ) { |
|
126 | - if ( in_array( $update['id'], $completed_updates ) ) { |
|
127 | - unset( $updates[ $index ] ); |
|
124 | + if ( ! empty($completed_updates)) { |
|
125 | + foreach ($updates as $index => $update) { |
|
126 | + if (in_array($update['id'], $completed_updates)) { |
|
127 | + unset($updates[$index]); |
|
128 | 128 | } |
129 | 129 | } |
130 | - $updates = array_values( $updates ); |
|
130 | + $updates = array_values($updates); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | break; |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @return static |
145 | 145 | */ |
146 | 146 | static function get_instance() { |
147 | - if ( is_null( self::$instance ) ) { |
|
147 | + if (is_null(self::$instance)) { |
|
148 | 148 | self::$instance = new self(); |
149 | 149 | } |
150 | 150 | |
@@ -162,16 +162,16 @@ discard block |
||
162 | 162 | /** |
163 | 163 | * Setup hooks. |
164 | 164 | */ |
165 | - add_action( 'init', array( $this, '__register_upgrade' ), 9999 ); |
|
166 | - add_action( 'admin_init', array( $this, '__change_donations_label' ), 9999 ); |
|
167 | - add_action( 'admin_menu', array( $this, '__register_menu' ), 9999 ); |
|
168 | - add_action( 'give_set_upgrade_completed', array( $this, '__flush_resume_updates' ), 9999 ); |
|
169 | - add_action( 'wp_ajax_give_do_ajax_updates', array( $this, '__give_ajax_updates' ) ); |
|
165 | + add_action('init', array($this, '__register_upgrade'), 9999); |
|
166 | + add_action('admin_init', array($this, '__change_donations_label'), 9999); |
|
167 | + add_action('admin_menu', array($this, '__register_menu'), 9999); |
|
168 | + add_action('give_set_upgrade_completed', array($this, '__flush_resume_updates'), 9999); |
|
169 | + add_action('wp_ajax_give_do_ajax_updates', array($this, '__give_ajax_updates')); |
|
170 | 170 | |
171 | 171 | /** |
172 | 172 | * Load file |
173 | 173 | */ |
174 | - require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php'; |
|
174 | + require_once GIVE_PLUGIN_DIR.'includes/admin/upgrades/upgrade-functions.php'; |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -184,12 +184,12 @@ discard block |
||
184 | 184 | $addons = give_get_plugins(); |
185 | 185 | $plugin_updates = get_plugin_updates(); |
186 | 186 | |
187 | - foreach ( $addons as $key => $info ) { |
|
188 | - if ( 'active' != $info['Status'] || 'add-on' != $info['Type'] || empty( $plugin_updates[ $key ] ) ) { |
|
187 | + foreach ($addons as $key => $info) { |
|
188 | + if ('active' != $info['Status'] || 'add-on' != $info['Type'] || empty($plugin_updates[$key])) { |
|
189 | 189 | continue; |
190 | 190 | } |
191 | 191 | |
192 | - $this->updates['plugin'][] = array_merge( $info, (array) $plugin_updates[ $key ] ); |
|
192 | + $this->updates['plugin'][] = array_merge($info, (array) $plugin_updates[$key]); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * @access public |
202 | 202 | */ |
203 | 203 | public function __register_upgrade() { |
204 | - if ( ! is_admin() ) { |
|
204 | + if ( ! is_admin()) { |
|
205 | 205 | return; |
206 | 206 | } |
207 | 207 | |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | * |
211 | 211 | * @since 1.8.12 |
212 | 212 | */ |
213 | - do_action( 'give_register_updates', $this ); |
|
213 | + do_action('give_register_updates', $this); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
@@ -224,17 +224,17 @@ discard block |
||
224 | 224 | global $submenu; |
225 | 225 | |
226 | 226 | // Bailout. |
227 | - if ( empty( $menu ) || ! $this->get_update_count() ) { |
|
227 | + if (empty($menu) || ! $this->get_update_count()) { |
|
228 | 228 | return; |
229 | 229 | } |
230 | 230 | |
231 | - foreach ( $menu as $index => $menu_item ) { |
|
232 | - if ( 'edit.php?post_type=give_forms' !== $menu_item[2] ) { |
|
231 | + foreach ($menu as $index => $menu_item) { |
|
232 | + if ('edit.php?post_type=give_forms' !== $menu_item[2]) { |
|
233 | 233 | continue; |
234 | 234 | } |
235 | 235 | |
236 | - $menu[ $index ][0] = sprintf( |
|
237 | - __( 'Donations %s', 'give' ), |
|
236 | + $menu[$index][0] = sprintf( |
|
237 | + __('Donations %s', 'give'), |
|
238 | 238 | sprintf( |
239 | 239 | '<span class="update-plugins count-%1$d"><span class="plugin-count">%1$d</span></span>', |
240 | 240 | $this->get_update_count() |
@@ -259,15 +259,15 @@ discard block |
||
259 | 259 | // Bailout. |
260 | 260 | if ( ! $this->get_update_count()) { |
261 | 261 | // Show complete update message if still on update setting page. |
262 | - if ( isset($_GET['page']) && 'give-updates' === $_GET['page'] ) { |
|
262 | + if (isset($_GET['page']) && 'give-updates' === $_GET['page']) { |
|
263 | 263 | // Upgrades |
264 | 264 | add_submenu_page( |
265 | 265 | 'edit.php?post_type=give_forms', |
266 | - esc_html__( 'Give Updates Complete', 'give' ), |
|
267 | - __( 'Updates', 'give' ), |
|
266 | + esc_html__('Give Updates Complete', 'give'), |
|
267 | + __('Updates', 'give'), |
|
268 | 268 | 'manage_give_settings', |
269 | 269 | 'give-updates', |
270 | - array( $this, 'render_complete_page' ) |
|
270 | + array($this, 'render_complete_page') |
|
271 | 271 | ); |
272 | 272 | } |
273 | 273 | |
@@ -277,15 +277,15 @@ discard block |
||
277 | 277 | // Upgrades |
278 | 278 | add_submenu_page( |
279 | 279 | 'edit.php?post_type=give_forms', |
280 | - esc_html__( 'Give Updates', 'give' ), |
|
280 | + esc_html__('Give Updates', 'give'), |
|
281 | 281 | sprintf( |
282 | 282 | '%1$s <span class="update-plugins count-%2$d"><span class="plugin-count">%2$d</span></span>', |
283 | - __( 'Updates', 'give' ), |
|
283 | + __('Updates', 'give'), |
|
284 | 284 | $this->get_update_count() |
285 | 285 | ), |
286 | 286 | 'manage_give_settings', |
287 | 287 | 'give-updates', |
288 | - array( $this, 'render_page' ) |
|
288 | + array($this, 'render_page') |
|
289 | 289 | ); |
290 | 290 | } |
291 | 291 | |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | * @return int |
298 | 298 | */ |
299 | 299 | public function get_db_update_count() { |
300 | - return count( $this->get_updates( 'database', 'new' ) ); |
|
300 | + return count($this->get_updates('database', 'new')); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | * @access public |
308 | 308 | */ |
309 | 309 | public function render_complete_page() { |
310 | - include_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/views/upgrades-complete.php'; |
|
310 | + include_once GIVE_PLUGIN_DIR.'includes/admin/upgrades/views/upgrades-complete.php'; |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | * @access public |
318 | 318 | */ |
319 | 319 | public function render_page() { |
320 | - include_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/views/upgrades.php'; |
|
320 | + include_once GIVE_PLUGIN_DIR.'includes/admin/upgrades/views/upgrades.php'; |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | * @return int |
329 | 329 | */ |
330 | 330 | public function get_plugin_update_count() { |
331 | - return count( $this->get_updates( 'plugin' ) ); |
|
331 | + return count($this->get_updates('plugin')); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | /** |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | $db_update_count = $this->get_db_update_count(); |
344 | 344 | $plugin_update_count = $this->get_plugin_update_count(); |
345 | 345 | |
346 | - return ( $db_update_count + $plugin_update_count ); |
|
346 | + return ($db_update_count + $plugin_update_count); |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | |
@@ -354,12 +354,12 @@ discard block |
||
354 | 354 | * @access public |
355 | 355 | */ |
356 | 356 | public function __flush_resume_updates() { |
357 | - delete_option( 'give_doing_upgrade' ); |
|
358 | - update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) ); |
|
357 | + delete_option('give_doing_upgrade'); |
|
358 | + update_option('give_version', preg_replace('/[^0-9.].*/', '', GIVE_VERSION)); |
|
359 | 359 | |
360 | 360 | // Reset counter. |
361 | 361 | $this->step = $this->percentage = 0; |
362 | - ++ $this->update; |
|
362 | + ++$this->update; |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -370,30 +370,30 @@ discard block |
||
370 | 370 | */ |
371 | 371 | public function __give_ajax_updates() { |
372 | 372 | // Check permission. |
373 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
373 | + if ( ! current_user_can('manage_give_settings')) { |
|
374 | 374 | $this->send_ajax_response( |
375 | 375 | array( |
376 | - 'message' => esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), |
|
376 | + 'message' => esc_html__('You do not have permission to do Give upgrades.', 'give'), |
|
377 | 377 | ), |
378 | 378 | 'error' |
379 | 379 | ); |
380 | 380 | } |
381 | 381 | |
382 | 382 | // Update timeout error. |
383 | - ignore_user_abort( true ); |
|
384 | - if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
|
385 | - @set_time_limit( 0 ); |
|
383 | + ignore_user_abort(true); |
|
384 | + if ( ! give_is_func_disabled('set_time_limit') && ! ini_get('safe_mode')) { |
|
385 | + @set_time_limit(0); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | // Set params. |
389 | - $this->step = absint( $_POST['step'] ); |
|
390 | - $this->update = absint( $_POST['update'] ); |
|
389 | + $this->step = absint($_POST['step']); |
|
390 | + $this->update = absint($_POST['update']); |
|
391 | 391 | |
392 | 392 | // Bailout: step and update must be positive and greater then zero. |
393 | - if ( ! $this->step ) { |
|
393 | + if ( ! $this->step) { |
|
394 | 394 | $this->send_ajax_response( |
395 | 395 | array( |
396 | - 'message' => __( 'Please reload this page and try again', 'give' ), |
|
396 | + 'message' => __('Please reload this page and try again', 'give'), |
|
397 | 397 | 'heading' => '', |
398 | 398 | 'percentage' => 0, |
399 | 399 | ), |
@@ -402,14 +402,14 @@ discard block |
||
402 | 402 | } |
403 | 403 | |
404 | 404 | // Get updates. |
405 | - $updates = $this->get_updates( 'database', 'new' ); |
|
405 | + $updates = $this->get_updates('database', 'new'); |
|
406 | 406 | |
407 | 407 | // Bailout if we do not have nay updates. |
408 | - if ( empty( $updates ) ) { |
|
408 | + if (empty($updates)) { |
|
409 | 409 | $this->send_ajax_response( |
410 | 410 | array( |
411 | - 'message' => __( 'The database is already up to date.', 'give' ), |
|
412 | - 'heading' => __( 'Updates Completed.', 'give' ), |
|
411 | + 'message' => __('The database is already up to date.', 'give'), |
|
412 | + 'heading' => __('Updates Completed.', 'give'), |
|
413 | 413 | 'percentage' => 0, |
414 | 414 | ), |
415 | 415 | 'success' |
@@ -417,26 +417,26 @@ discard block |
||
417 | 417 | } |
418 | 418 | |
419 | 419 | // Process update. |
420 | - foreach ( $updates as $index => $update ) { |
|
420 | + foreach ($updates as $index => $update) { |
|
421 | 421 | // Check if update depend upon any other update. |
422 | - if ( ! empty( $update['depend'] ) && ! give_has_upgrade_completed( $update['depend'] ) ) { |
|
422 | + if ( ! empty($update['depend']) && ! give_has_upgrade_completed($update['depend'])) { |
|
423 | 423 | continue; |
424 | 424 | } |
425 | 425 | |
426 | 426 | // Run update. |
427 | - if ( is_array( $update['callback'] ) ) { |
|
427 | + if (is_array($update['callback'])) { |
|
428 | 428 | $update['callback'][0]->$update['callback'][1](); |
429 | 429 | } else { |
430 | 430 | $update['callback'](); |
431 | 431 | } |
432 | 432 | |
433 | 433 | // Check if current update completed or not. |
434 | - if ( give_has_upgrade_completed( $update['id'] ) ) { |
|
435 | - if ( 1 === count( $updates ) ) { |
|
434 | + if (give_has_upgrade_completed($update['id'])) { |
|
435 | + if (1 === count($updates)) { |
|
436 | 436 | $this->send_ajax_response( |
437 | 437 | array( |
438 | - 'message' => __( 'Database updated successfully.', 'give' ), |
|
439 | - 'heading' => __( 'Updates Completed.', 'give' ), |
|
438 | + 'message' => __('Database updated successfully.', 'give'), |
|
439 | + 'heading' => __('Updates Completed.', 'give'), |
|
440 | 440 | 'percentage' => 0, |
441 | 441 | ), |
442 | 442 | 'success' |
@@ -446,16 +446,16 @@ discard block |
||
446 | 446 | |
447 | 447 | $doing_upgrade_args = array( |
448 | 448 | 'update_info' => $update, |
449 | - 'step' => ++ $this->step, |
|
449 | + 'step' => ++$this->step, |
|
450 | 450 | 'update' => $this->update, |
451 | - 'heading' => sprintf( 'Update %s of {update_count}', $this->update ), |
|
451 | + 'heading' => sprintf('Update %s of {update_count}', $this->update), |
|
452 | 452 | 'percentage' => $this->percentage, |
453 | 453 | ); |
454 | 454 | |
455 | 455 | // Cache upgrade. |
456 | - update_option( 'give_doing_upgrade', $doing_upgrade_args ); |
|
456 | + update_option('give_doing_upgrade', $doing_upgrade_args); |
|
457 | 457 | |
458 | - $this->send_ajax_response( $doing_upgrade_args ); |
|
458 | + $this->send_ajax_response($doing_upgrade_args); |
|
459 | 459 | }// End foreach(). |
460 | 460 | } |
461 | 461 | |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | * @param $data |
469 | 469 | * @param string $type |
470 | 470 | */ |
471 | - public function send_ajax_response( $data, $type = '' ) { |
|
471 | + public function send_ajax_response($data, $type = '') { |
|
472 | 472 | $default = array( |
473 | 473 | 'message' => '', |
474 | 474 | 'heading' => '', |
@@ -478,21 +478,21 @@ discard block |
||
478 | 478 | ); |
479 | 479 | |
480 | 480 | // Set data. |
481 | - $data = wp_parse_args( $data, $default ); |
|
481 | + $data = wp_parse_args($data, $default); |
|
482 | 482 | |
483 | - switch ( $type ) { |
|
483 | + switch ($type) { |
|
484 | 484 | case 'success': |
485 | - wp_send_json_success( $data ); |
|
485 | + wp_send_json_success($data); |
|
486 | 486 | break; |
487 | 487 | |
488 | 488 | case 'error': |
489 | - wp_send_json_error( $data ); |
|
489 | + wp_send_json_error($data); |
|
490 | 490 | break; |
491 | 491 | |
492 | 492 | default: |
493 | - wp_send_json( array( |
|
493 | + wp_send_json(array( |
|
494 | 494 | 'data' => $data, |
495 | - ) ); |
|
495 | + )); |
|
496 | 496 | break; |
497 | 497 | } |
498 | 498 | } |
@@ -509,8 +509,8 @@ discard block |
||
509 | 509 | public function resume_updates() { |
510 | 510 | $status = false; |
511 | 511 | |
512 | - if ( $update = get_option( 'give_doing_upgrade' ) ) { |
|
513 | - $status = ! empty( $update['step'] ) ? $update['step'] : $status; |
|
512 | + if ($update = get_option('give_doing_upgrade')) { |
|
513 | + $status = ! empty($update['step']) ? $update['step'] : $status; |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | return $status; |
@@ -526,12 +526,12 @@ discard block |
||
526 | 526 | * @param $total |
527 | 527 | * @param $current_total |
528 | 528 | */ |
529 | - public function set_percentage( $total, $current_total ) { |
|
529 | + public function set_percentage($total, $current_total) { |
|
530 | 530 | // Set percentage. |
531 | - $this->percentage = $total ? ( ( $current_total ) / $total ) * 100 : 0; |
|
531 | + $this->percentage = $total ? (($current_total) / $total) * 100 : 0; |
|
532 | 532 | |
533 | 533 | // Verify percentage. |
534 | - $this->percentage = ( 100 < $this->percentage ) ? 100 : $this->percentage; |
|
534 | + $this->percentage = (100 < $this->percentage) ? 100 : $this->percentage; |
|
535 | 535 | } |
536 | 536 | } |
537 | 537 |