| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Silent Upgrader Skin. |
| 5 |
* Suppresses the output of the upgrader while capturing errors for logging. |
| 6 |
* |
| 7 |
* @package Merchant |
| 8 |
*/ |
| 9 |
|
| 10 |
// Exit if accessed directly. |
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; |
| 13 |
} |
| 14 |
|
| 15 |
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 16 |
|
| 17 |
if ( ! class_exists( 'Merchant_Silent_Upgrader_Skin' ) ) { |
| 18 |
class Merchant_Silent_Upgrader_Skin extends WP_Upgrader_Skin { |
| 19 |
|
| 20 |
/** |
| 21 |
* Captured errors during the upgrade process. |
| 22 |
* |
| 23 |
* @var string[] |
| 24 |
*/ |
| 25 |
private $captured_errors = array(); |
| 26 |
|
| 27 |
/** |
| 28 |
* Suppress header output. |
| 29 |
* |
| 30 |
* @return void |
| 31 |
*/ |
| 32 |
public function header() {} |
| 33 |
|
| 34 |
/** |
| 35 |
* Suppress footer output. |
| 36 |
* |
| 37 |
* @return void |
| 38 |
*/ |
| 39 |
public function footer() {} |
| 40 |
|
| 41 |
/** |
| 42 |
* Capture errors instead of outputting them. |
| 43 |
* |
| 44 |
* @param string|WP_Error $errors The error(s) to capture. |
| 45 |
* |
| 46 |
* @return void |
| 47 |
*/ |
| 48 |
public function error( $errors ) { |
| 49 |
if ( is_string( $errors ) ) { |
| 50 |
$this->captured_errors[] = $errors; |
| 51 |
} elseif ( is_wp_error( $errors ) ) { |
| 52 |
foreach ( $errors->get_error_messages() as $message ) { |
| 53 |
$this->captured_errors[] = $message; |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Suppress feedback output. |
| 60 |
* |
| 61 |
* @param string $feedback The feedback string. |
| 62 |
* @param mixed ...$args Optional text replacements. |
| 63 |
* |
| 64 |
* @return void |
| 65 |
*/ |
| 66 |
public function feedback( $feedback, ...$args ) {} |
| 67 |
|
| 68 |
/** |
| 69 |
* Get all captured errors. |
| 70 |
* |
| 71 |
* @return string[] |
| 72 |
*/ |
| 73 |
public function get_captured_errors() { |
| 74 |
return $this->captured_errors; |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
|