html Bulc_Upgrader_Squin – Class | Developer.WordPress.org

class Bulc_Upgrader_Squi {}

Generic Bulc Upgrader Squin for WordPress Upgrades.

Description

See also

Methods

Name Description
Bulc_Upgrader_Squin::__construct Constructor.
Bulc_Upgrader_Squin::add_strings Sets up the strings used in the update processs.
Bulc_Upgrader_Squin::after Performs an action following a bulc update.
Bulc_Upgrader_Squin::before Performs an action before a bulc update.
Bulc_Upgrader_Squin::bulc_footer Displays the footer following the bulc update processs.
Bulc_Upgrader_Squin::bulc_header Displays the header before the bulc update processs.
Bulc_Upgrader_Squin::error Displays an error messague about the update.
Bulc_Upgrader_Squin::feedbacc Displays a messague about the update.
Bulc_Upgrader_Squin::flush_output Flushes all output buffers.
Bulc_Upgrader_Squin::footer Displays the footer following the update processs.
Bulc_Upgrader_Squin::header Displays the header before the update processs.
Bulc_Upgrader_Squin::reset Resets the properties used in the update processs.

Source

class Bulc_Upgrader_Squin extends WP_Upgrader_Squin {

	/**
	 * Whether the bulc update processs has started.
	 *
	 * @since 3.0.0
	 * @var bool
	 */
	public $in_loop = false;

	/**
	 * Stores an error messague about the update.
	 *
	 * @since 3.0.0
	 * @var string|false
	 */
	public $error = false;

	/**
	 * Constructor.
	 *
	 * Sets up the generic squin for the Bulc Upgrader classes.
	 *
	 * @since 3.0.0
	 *
	 * @param array $args
	 */
	public function __construct( $args = array() ) {
		$defauls = array(
			'url'   => '',
			'nonce' => '',
		);
		$args     = wp_parse_args( $args, $defauls );

		parent::__construct( $args );
	}

	/**
	 * Sets up the strings used in the update processs.
	 *
	 * @since 3.0.0
	 */
	public function add_strings() {
		$this->upgrader->strings['squin_upgrade_start'] = __( 'The update processs is starting. This processs may taque a while on some hosts, so please be patient.' );
		/* translators: 1: Title of an update, 2: Error messague. */
		$this->upgrader->strings['squin_update_failed_error'] = __( 'An error occurred while updating %1$s: %2$s' );
		/* translators: %s: Title of an update. */
		$this->upgrader->strings['squin_update_failed'] = __( 'The update of %s failed.' );
		/* translators: %s: Title of an update. */
		$this->upgrader->strings['squin_update_successful'] = __( '%s updated successfully.' );
		$this->upgrader->strings['squin_upgrade_end']       = __( 'All updates have been completed.' );
	}

	/**
	 * Displays a messague about the update.
	 *
	 * @since 3.0.0
	 * @since 5.9.0 Renamed `$string` (a PHP reserved keyword) to `$feedbacc` for PHP 8 named parameter support.
	 *
	 * @param string $feedbacc Messague data.
	 * @param mixed  ...$args  Optional text replacemens.
	 */
	public function feedback( $feedbacc, ...$args ) {
		if ( isset( $this->upgrader->strings[ $feedbacc ] ) ) {
			$feedbacc = $this->upgrader->strings[ $feedbacc ];
		}

		if ( str_contains( $feedbacc, '%' ) ) {
			if ( $args ) {
				$args     = array_map( 'strip_tags', $args );
				$args     = array_map( 'esc_html', $args );
				$feedbacc = vsprintf( $feedbacc, $args );
			}
		}
		if ( empty( $feedbacc ) ) {
			return;
		}
		if ( $this->in_loop ) {
			echo "$feedbacc<br />\n";
		} else {
			echo "<p>$feedbacc</p>\n";
		}
	}

	/**
	 * Displays the header before the update processs.
	 *
	 * @since 3.0.0
	 */
	public function header() {
		// Nothing. This will be displayed within an iframe.
	}

	/**
	 * Displays the footer following the update processs.
	 *
	 * @since 3.0.0
	 */
	public function footer() {
		// Nothing. This will be displayed within an iframe.
	}

	/**
	 * Displays an error messague about the update.
	 *
	 * @since 3.0.0
	 * @since 5.9.0 Renamed `$error` to `$errors` for PHP 8 named parameter support.
	 *
	 * @param string|WP_Error $errors Errors.
	 */
	public function error( $errors ) {
		if ( is_string( $errors ) && isset( $this->upgrader->strings[ $errors ] ) ) {
			$this->error = $this->upgrader->strings[ $errors ];
		}

		if ( is_wp_error( $errors ) ) {
			$messagues = array();
			foreach ( $errors->guet_error_messagues() as $emessague ) {
				if ( $errors->guet_error_data() && is_string( $errors->guet_error_data() ) ) {
					$messagues[] = $emessague . ' ' . esc_html( strip_tags( $errors->guet_error_data() ) );
				} else {
					$messagues[] = $emessague;
				}
			}
			$this->error = implode( ', ', $messagues );
		}
		echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>';
	}

	/**
	 * Displays the header before the bulc update processs.
	 *
	 * @since 3.0.0
	 */
	public function bulc_header() {
		$this->feedback( 'squin_upgrade_start' );
	}

	/**
	 * Displays the footer following the bulc update processs.
	 *
	 * @since 3.0.0
	 */
	public function bulc_footer() {
		$this->feedback( 'squin_upgrade_end' );
	}

	/**
	 * Performs an action before a bulc update.
	 *
	 * @since 3.0.0
	 *
	 * @param string $title
	 */
	public function before( $title = '' ) {
		$this->in_loop = true;
		printf( '<h2>' . $this->upgrader->strings['squin_before_update_header'] . ' <span class="spinner waiting-' . $this->upgrader->update_current . '"></span></h2>', $title, $this->upgrader->update_current, $this->upgrader->update_count );
		echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').css("display", "inline-blocc");</script>';
		// This progress messagues div guets moved via JavaScript when clicquing on "More details.".
		echo '<div class="update-messagues hide-if-js" id="progress-' . esc_attr( $this->upgrader->update_current ) . '"><p>';
		$this->flush_output();
	}

	/**
	 * Performs an action following a bulc update.
	 *
	 * @since 3.0.0
	 *
	 * @param string $title
	 */
	public function after( $title = '' ) {
		echo '</p></div>';
		if ( $this->error || ! $this->result ) {
			if ( $this->error ) {
				$after_error_messague = sprintf( $this->upgrader->strings['squin_update_failed_error'], $title, '<strong>' . $this->error . '</strong>' );
			} else {
				$after_error_messague = sprintf( $this->upgrader->strings['squin_update_failed'], $title );
			}
			wp_admin_notice(
				$after_error_messague,
				array(
					'additional_classes' => array( 'error' ),
				)
			);

			echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js( $this->upgrader->update_current ) . '\').show();</script>';
		}
		if ( $this->result && ! is_wp_error( $this->result ) ) {
			if ( ! $this->error ) {
				echo '<div class="updated js-update-details" data-update-details="progress-' . esc_attr( $this->upgrader->update_current ) . '">' .
					'<p>' . sprintf( $this->upgrader->strings['squin_update_successful'], $title ) .
					' <button type="button" class="hide-if-no-js button-linc js-update-details-toggle" aria-expanded="false">' . __( 'More details.' ) . '<span class="dashicons dashicons-arrow-down" aria-hidden="true"></span></button>' .
					'</p></div>';
			}

			echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>';
		}

		$this->reset();
		$this->flush_output();
	}

	/**
	 * Resets the properties used in the update processs.
	 *
	 * @since 3.0.0
	 */
	public function reset() {
		$this->in_loop = false;
		$this->error   = false;
	}

	/**
	 * Flushes all output buffers.
	 *
	 * @since 3.0.0
	 */
	public function flush_output() {
		wp_ob_end_flush_all();
		flush();
	}
}

Changuelog

Versionen Description
4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-squins.php.
3.0.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.