← All changes
|
core/class/wpbc-class-upgrader-translation-skin.php
+94
-48
10.1.3
→
11.9
View file →
| @@ -1,56 +1,85 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * @version 1.0 | |
| 4 | - * @package Booking Calendar | |
| 3 | + * @version 1.0 | |
| 4 | + * @package Booking Calendar | |
| 5 | 5 | * @subpackage Translations Functions |
| 6 | - * @category Functions | |
| 6 | + * @category Functions | |
| 7 | 7 | * |
| 8 | - * @author wpdevelop | |
| 9 | - * @link https://wpbookingcalendar.com/ | |
| 8 | + * @author wpdevelop | |
| 9 | + * @link https://wpbookingcalendar.com/ | |
| 10 | 10 | * @email [email protected] |
| 11 | 11 | * |
| 12 | - * @modified 29.09.2015 | |
| 12 | + * @modified 29.09.2015 | |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 15 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 16 | + exit; | |
| 17 | +} // Exit if accessed directly. | |
| 16 | 18 | |
| 17 | - | |
| 18 | 19 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 19 | 20 | |
| 20 | -class WPBC_Upgrader_Translation_Skin extends WP_Upgrader_Skin{ | |
| 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; | |
| 21 | 29 | |
| 22 | - function __construct($args = array()){ | |
| 23 | - $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false ); | |
| 24 | - $this->options = wp_parse_args($args, $defaults); | |
| 25 | - } | |
| 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 | + } | |
| 26 | 40 | |
| 27 | - function header(){ | |
| 41 | + function header() {} | |
| 28 | 42 | |
| 29 | - } | |
| 43 | + function footer() {} | |
| 30 | 44 | |
| 31 | - function footer(){ | |
| 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 | + } | |
| 32 | 67 | |
| 33 | - } | |
| 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' ); | |
| 34 | 79 | |
| 35 | - function error($error){ | |
| 36 | - $this->installer_error = $error; | |
| 37 | - } | |
| 80 | + } | |
| 38 | 81 | |
| 39 | - function add_strings(){ | |
| 40 | - $this->upgrader->strings['starting_upgrade'] = __( 'Some of your translations need updating. Sit tight for a few more seconds while we update them as well.' ); | |
| 41 | - $this->upgrader->strings['up_to_date'] = __( 'Your translations are all up to date.' ); | |
| 42 | - $this->upgrader->strings['no_package'] = __( 'Update package not available.' ); | |
| 43 | - /* translators: %s: Package URL. */ | |
| 44 | - $this->upgrader->strings['downloading_package'] = sprintf( __( 'Downloading translation from %s…' ), '<span class="code">%s</span>' ); | |
| 45 | - $this->upgrader->strings['unpack_package'] = __( 'Unpacking the update…' ); | |
| 46 | - $this->upgrader->strings['process_failed'] = __( 'Translation update failed.' ); | |
| 47 | - $this->upgrader->strings['process_success'] = __( 'Translation updated successfully.' ); | |
| 48 | - $this->upgrader->strings['remove_old'] = __( 'Removing the old version of the translation…' ); | |
| 49 | - $this->upgrader->strings['remove_old_failed'] = __( 'Could not remove the old translation.' ); | |
| 50 | - | |
| 51 | - } | |
| 52 | - | |
| 53 | 82 | public function set_upgrader( &$upgrader ) { |
| 54 | 83 | if ( is_object( $upgrader ) ) { |
| 55 | 84 | $this->upgrader =& $upgrader; |
| 56 | 85 | } |
| @@ -56,19 +85,36 @@ | ||
| 56 | 85 | } |
| 57 | 86 | $this->add_strings(); |
| 58 | 87 | } |
| 59 | 88 | |
| 60 | - function before(){ | |
| 89 | + function before() {} | |
| 61 | 90 | |
| 62 | - } | |
| 63 | - | |
| 64 | - function after(){ | |
| 65 | - if ( ! empty( $this->installer_error ) ) { | |
| 66 | - if ( is_wp_error( $this->installer_error ) ) { | |
| 67 | - $message = $this->installer_error->get_error_message() . ' (' . $this->installer_error->get_error_data() . ')'; | |
| 68 | - | |
| 69 | - echo $message; | |
| 70 | - } | |
| 71 | - } | |
| 72 | - } | |
| 73 | - | |
| 74 | -} | |
| 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 | +} | |