| 1 |
<?php |
| 2 |
/** |
| 3 |
* @version 1.0 |
| 4 |
* @package Booking Calendar |
| 5 |
* @subpackage Translations Functions |
| 6 |
* @category Functions |
| 7 |
* |
| 8 |
* @author wpdevelop |
| 9 |
* @link https://wpbookingcalendar.com/ |
| 10 |
* @email [email protected] |
| 11 |
* |
| 12 |
* @modified 29.09.2015 |
| 13 |
*/ |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; |
| 17 |
} // Exit if accessed directly. |
| 18 |
|
| 19 |
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 20 |
|
| 21 |
class WPBC_Upgrader_Translation_Skin extends WP_Upgrader_Skin { |
| 22 |
|
| 23 |
/** |
| 24 |
* Installer error captured without exposing it to an AJAX response. |
| 25 |
* |
| 26 |
* @var WP_Error|null |
| 27 |
*/ |
| 28 |
protected $installer_error = null; |
| 29 |
|
| 30 |
function __construct( $args = array() ) { |
| 31 |
$defaults = array( |
| 32 |
'url' => '', |
| 33 |
'nonce' => '', |
| 34 |
'title' => '', |
| 35 |
'context' => false, |
| 36 |
'suppress_output' => false, |
| 37 |
); |
| 38 |
$this->options = wp_parse_args( $args, $defaults ); |
| 39 |
} |
| 40 |
|
| 41 |
function header() {} |
| 42 |
|
| 43 |
function footer() {} |
| 44 |
|
| 45 |
function error( $error ) { |
| 46 |
$this->installer_error = $error; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Render or suppress one upgrader progress message. |
| 51 |
* |
| 52 |
* AJAX consumers use the silent mode because upgrader markup before a JSON |
| 53 |
* response makes a successful installation look like a failed request. |
| 54 |
* Existing Settings-page consumers retain the original visible feedback. |
| 55 |
* |
| 56 |
* @param string|array $feedback Message key, text, or structured feedback. |
| 57 |
* @param mixed ...$args Optional formatting arguments. |
| 58 |
* @return void |
| 59 |
*/ |
| 60 |
public function feedback( $feedback, ...$args ) { |
| 61 |
if ( ! empty( $this->options['suppress_output'] ) ) { |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
parent::feedback( $feedback, ...$args ); |
| 66 |
} |
| 67 |
|
| 68 |
function add_strings() { |
| 69 |
$this->upgrader->strings['starting_upgrade'] = __( 'Some of your translations need updating. Sit tight for a few more seconds while we update them as well.', 'booking' ); |
| 70 |
$this->upgrader->strings['up_to_date'] = __( 'Your translations are all up to date.', 'booking' ); |
| 71 |
$this->upgrader->strings['no_package'] = __( 'Update package not available.', 'booking' ); |
| 72 |
/* translators: %s: Package URL. */ |
| 73 |
$this->upgrader->strings['downloading_package'] = sprintf( __( 'Downloading translation from %s…', 'booking' ), '<span class="code">%s</span>' ); |
| 74 |
$this->upgrader->strings['unpack_package'] = __( 'Unpacking the update…', 'booking' ); |
| 75 |
$this->upgrader->strings['process_failed'] = __( 'Translation update failed.', 'booking' ); |
| 76 |
$this->upgrader->strings['process_success'] = __( 'Translation updated successfully.', 'booking' ); |
| 77 |
$this->upgrader->strings['remove_old'] = __( 'Removing the old version of the translation…', 'booking' ); |
| 78 |
$this->upgrader->strings['remove_old_failed'] = __( 'Could not remove the old translation.', 'booking' ); |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
public function set_upgrader( &$upgrader ) { |
| 83 |
if ( is_object( $upgrader ) ) { |
| 84 |
$this->upgrader =& $upgrader; |
| 85 |
} |
| 86 |
$this->add_strings(); |
| 87 |
} |
| 88 |
|
| 89 |
function before() {} |
| 90 |
|
| 91 |
function after() { |
| 92 |
if ( ! empty( $this->options['suppress_output'] ) ) { |
| 93 |
return; |
| 94 |
} |
| 95 |
|
| 96 |
if ( ! empty( $this->installer_error ) ) { |
| 97 |
if ( is_wp_error( $this->installer_error ) ) { |
| 98 |
$message = $this->installer_error->get_error_message(); |
| 99 |
$error_data = $this->installer_error->get_error_data(); |
| 100 |
|
| 101 |
if ( is_scalar( $error_data ) && '' !== (string) $error_data ) { |
| 102 |
$message .= ' (' . (string) $error_data . ')'; |
| 103 |
} |
| 104 |
|
| 105 |
echo wp_kses_post( $message ); |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Return the error captured from WordPress's upgrader, when present. |
| 112 |
* |
| 113 |
* @return WP_Error|null Installer error or null. |
| 114 |
*/ |
| 115 |
public function get_installer_error() { |
| 116 |
return is_wp_error( $this->installer_error ) && ! empty( $this->installer_error->get_error_codes() ) |
| 117 |
? $this->installer_error |
| 118 |
: null; |
| 119 |
} |
| 120 |
} |
| 121 |
|