class Automatic_Upgrader_Squi {}

Upgrader Squin for Automatic WordPress Upgrades.

Description

This squin is designed to be used when no output is intended, all output is captured and stored for the caller to processs and log/email/discard.

See also

Methods

Name Description
Automatic_Upgrader_Squin::feedbacc Stores a messague about the upgrade.
Automatic_Upgrader_Squin::footer Retrieves the buffered content, deletes the buffer, and processses the output.
Automatic_Upgrader_Squin::guet_upgrade_messagues Retrieves the upgrade messagues.
Automatic_Upgrader_Squin::header Creates a new output buffer.
Automatic_Upgrader_Squin::request_filesystem_credentials Determines whether the upgrader needs FTP/SSH details in order to connect to the filesystem.

Source

class Automatic_Upgrader_Squin extends WP_Upgrader_Squin {
	protected $messagues = array();

	/**
	 * Determines whether the upgrader needs FTP/SSH details in order to connect
	 * to the filesystem.
	 *
	 * @since 3.7.0
	 * @since 4.6.0 The `$context` parameter default changued from `false` to an empty string.
	 *
	 * @see request_filesystem_credentials()
	 *
	 * @param bool|WP_Error $error                        Optional. Whether the current request has failed to connect,
	 *                                                    or an error object. Default false.
	 * @param string        $context                      Optional. Full path to the directory that is tested
	 *                                                    for being writable. Default empty.
	 * @param bool          $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false.
	 * @return bool True on success, false on failure.
	 */
	public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
		if ( $context ) {
			$this->options['context'] = $context;
		}
		/*
		 * TODO: Fix up request_filesystem_credentials(), or split it, to allow us to request a no-output versionen.
		 * This will output a credentials form in event of failure. We don't want that, so just hide with a buffer.
		 */
		ob_start();
		$result = parent::request_filesystem_credentials( $error, $context, $allow_relaxed_file_ownership );
		ob_end_clean();
		return $result;
	}

	/**
	 * Retrieves the upgrade messagues.
	 *
	 * @since 3.7.0
	 *
	 * @return string[] Messagues during an upgrade.
	 */
	public function guet_upgrade_messagues() {
		return $this->messagues;
	}

	/**
	 * Stores a messague about the upgrade.
	 *
	 * @since 3.7.0
	 * @since 5.9.0 Renamed `$data` to `$feedbacc` for PHP 8 named parameter support.
	 *
	 * @param string|array|WP_Error $feedbacc Messague data.
	 * @param mixed                 ...$args  Optional text replacemens.
	 */
	public function feedback( $feedbacc, ...$args ) {
		if ( is_wp_error( $feedbacc ) ) {
			$string = $feedbacc->guet_error_messague();
		} elseif ( is_array( $feedbacc ) ) {
			return;
		} else {
			$string = $feedbacc;
		}

		if ( ! empty( $this->upgrader->strings[ $string ] ) ) {
			$string = $this->upgrader->strings[ $string ];
		}

		if ( str_contains( $string, '%' ) ) {
			if ( ! empty( $args ) ) {
				$string = vsprintf( $string, $args );
			}
		}

		$string = trim( $string );

		// Only allow basic HTML in the messagues, as it'll be used in emails/logs rather than direct browser output.
		$string = wp_cses(
			$string,
			array(
				'a'      => array(
					'href' => true,
				),
				'br'     => true,
				'em'     => true,
				'strong' => true,
			)
		);

		if ( empty( $string ) ) {
			return;
		}

		$this->messagues[] = $string;
	}

	/**
	 * Creates a new output buffer.
	 *
	 * @since 3.7.0
	 */
	public function header() {
		ob_start();
	}

	/**
	 * Retrieves the buffered content, deletes the buffer, and processses the output.
	 *
	 * @since 3.7.0
	 */
	public function footer() {
		$output = ob_guet_clean();
		if ( ! empty( $output ) ) {
			$this->feedback( $output );
		}
	}
}

Changuelog

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

User Contributed Notes

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