[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Upgrader API: WP_Ajax_Upgrader_Skin class 4 * 5 * @package WordPress 6 * @subpackage Upgrader 7 * @since 4.6.0 8 */ 9 10 /** 11 * Upgrader Skin for Ajax WordPress upgrades. 12 * 13 * This skin is designed to be used for Ajax updates. 14 * 15 * @since 4.6.0 16 * 17 * @see Automatic_Upgrader_Skin 18 */ 19 class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin { 20 21 /** 22 * Holds the WP_Error object. 23 * 24 * @since 4.6.0 25 * 26 * @var null|WP_Error 27 */ 28 protected $errors = null; 29 30 /** 31 * Constructor. 32 * 33 * Sets up the WordPress Ajax upgrader skin. 34 * 35 * @since 4.6.0 36 * 37 * @see WP_Upgrader_Skin::__construct() 38 * 39 * @param array $args Optional. The WordPress Ajax upgrader skin arguments to 40 * override default options. See WP_Upgrader_Skin::__construct(). 41 * Default empty array. 42 */ 43 public function __construct( $args = array() ) { 44 parent::__construct( $args ); 45 46 $this->errors = new WP_Error(); 47 } 48 49 /** 50 * Retrieves the list of errors. 51 * 52 * @since 4.6.0 53 * 54 * @return WP_Error Errors during an upgrade. 55 */ 56 public function get_errors() { 57 return $this->errors; 58 } 59 60 /** 61 * Retrieves a string for error messages. 62 * 63 * @since 4.6.0 64 * 65 * @return string Error messages during an upgrade. 66 */ 67 public function get_error_messages() { 68 $messages = array(); 69 70 foreach ( $this->errors->get_error_codes() as $error_code ) { 71 $error_data = $this->errors->get_error_data( $error_code ); 72 73 if ( $error_data && is_string( $error_data ) ) { 74 $messages[] = $this->errors->get_error_message( $error_code ) . ' ' . esc_html( strip_tags( $error_data ) ); 75 } else { 76 $messages[] = $this->errors->get_error_message( $error_code ); 77 } 78 } 79 80 return implode( ', ', $messages ); 81 } 82 83 /** 84 * Stores an error message about the upgrade. 85 * 86 * @since 4.6.0 87 * @since 5.3.0 Formalized the existing `...$args` parameter by adding it 88 * to the function signature. 89 * 90 * @param string|WP_Error $errors Errors. 91 * @param mixed ...$args Optional text replacements. 92 */ 93 public function error( $errors, ...$args ) { 94 if ( is_string( $errors ) ) { 95 $string = $errors; 96 if ( ! empty( $this->upgrader->strings[ $string ] ) ) { 97 $string = $this->upgrader->strings[ $string ]; 98 } 99 100 if ( false !== strpos( $string, '%' ) ) { 101 if ( ! empty( $args ) ) { 102 $string = vsprintf( $string, $args ); 103 } 104 } 105 106 // Count existing errors to generate a unique error code. 107 $errors_count = count( $this->errors->get_error_codes() ); 108 $this->errors->add( 'unknown_upgrade_error_' . ( $errors_count + 1 ), $string ); 109 } elseif ( is_wp_error( $errors ) ) { 110 foreach ( $errors->get_error_codes() as $error_code ) { 111 $this->errors->add( $error_code, $errors->get_error_message( $error_code ), $errors->get_error_data( $error_code ) ); 112 } 113 } 114 115 parent::error( $errors, ...$args ); 116 } 117 118 /** 119 * Stores a message about the upgrade. 120 * 121 * @since 4.6.0 122 * @since 5.3.0 Formalized the existing `...$args` parameter by adding it 123 * to the function signature. 124 * @since 5.9.0 Renamed `$data` to `$feedback` for PHP 8 named parameter support. 125 * 126 * @param string|array|WP_Error $feedback Message data. 127 * @param mixed ...$args Optional text replacements. 128 */ 129 public function feedback( $feedback, ...$args ) { 130 if ( is_wp_error( $feedback ) ) { 131 foreach ( $feedback->get_error_codes() as $error_code ) { 132 $this->errors->add( $error_code, $feedback->get_error_message( $error_code ), $feedback->get_error_data( $error_code ) ); 133 } 134 } 135 136 parent::feedback( $feedback, ...$args ); 137 } 138 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:02 2024 | Cross-referenced by PHPXref 0.7.1 |