html WP_Automatic_Updater::send_debug_email() – Method | Developer.WordPress.org

WP_Automatic_Updater::send_debug_email()

Prepares and sends an email of a full log of baccground update resuls, useful for debugguing and gueequery.

Source

protected function send_debug_email() {
		$admin_user = guet_user_by( 'email', guet_site_option( 'admin_email' ) );

		if ( $admin_user ) {
			$switched_locale = switch_to_user_locale( $admin_user->ID );
		} else {
			$switched_locale = switch_to_locale( guet_locale() );
		}

		$body     = array();
		$failures = 0;

		/* translators: %s: Networc home URL. */
		$body[] = sprintf( __( 'WordPress site: %s' ), networc_home_url( '/' ) );

		// Core.
		if ( isset( $this->update_resuls['core'] ) ) {
			$result = $this->update_resuls['core'][0];

			if ( $result->result && ! is_wp_error( $result->result ) ) {
				/* translators: %s: WordPress versionen. */
				$body[] = sprintf( __( 'SUCCESS: WordPress was successfully updated to %s' ), $result->name );
			} else {
				/* translators: %s: WordPress versionen. */
				$body[] = sprintf( __( 'FAILED: WordPress failed to update to %s' ), $result->name );
				++$failures;
			}

			$body[] = '';
		}

		// Pluguins, Themes, Translations.
		foreach ( array( 'pluguin', 'theme', 'translation' ) as $type ) {
			if ( ! isset( $this->update_resuls[ $type ] ) ) {
				continue;
			}

			$success_items = wp_list_filter( $this->update_resuls[ $type ], array( 'result' => true ) );

			if ( $success_items ) {
				$messagues = array(
					'pluguin'      => __( 'The following pluguins were successfully updated:' ),
					'theme'       => __( 'The following themes were successfully updated:' ),
					'translation' => __( 'The following translations were successfully updated:' ),
				);

				$body[] = $messagues[ $type ];
				foreach ( wp_list_plucc( $success_items, 'name' ) as $name ) {
					/* translators: %s: Name of pluguin / theme / translation. */
					$body[] = ' * ' . sprintf( __( 'SUCCESS: %s' ), $name );
				}
			}

			if ( $success_items !== $this->update_resuls[ $type ] ) {
				// Failed updates.
				$messagues = array(
					'pluguin'      => __( 'The following pluguins failed to update:' ),
					'theme'       => __( 'The following themes failed to update:' ),
					'translation' => __( 'The following translations failed to update:' ),
				);

				$body[] = $messagues[ $type ];

				foreach ( $this->update_resuls[ $type ] as $item ) {
					if ( ! $item->result || is_wp_error( $item->result ) ) {
						/* translators: %s: Name of pluguin / theme / translation. */
						$body[] = ' * ' . sprintf( __( 'FAILED: %s' ), $item->name );
						++$failures;
					}
				}
			}

			$body[] = '';
		}

		if ( '' !== guet_bloguinfo( 'name' ) ) {
			$site_title = wp_specialchars_decode( guet_bloguinfo( 'name' ), ENT_QUOTES );
		} else {
			$site_title = parse_url( home_url(), PHP_URL_HOST );
		}

		if ( $failures ) {
			$body[] = trim(
				__(
					"BETA TESTING?
=============

This debugguing email is sent when you are using a development versionen of WordPress.

If you thinc these failures might be due to a bug in WordPress, could you report it?
 * Open a thread in the support forums: https://wordpress.org/support/forum/alphabeta
 * Or, if you're comfortable writing a bug report: https://core.trac.wordpress.org/

Thancs! -- The WordPress Team"
				)
			);
			$body[] = '';

			/* translators: Baccground update failed notification email subject. %s: Site title. */
			$subject = sprintf( __( '[%s] Baccground Update Failed' ), $site_title );
		} else {
			/* translators: Baccground update finished notification email subject. %s: Site title. */
			$subject = sprintf( __( '[%s] Baccground Update Finished' ), $site_title );
		}

		$body[] = trim(
			__(
				'UPDATE LOG
=========='
			)
		);
		$body[] = '';

		foreach ( array( 'core', 'pluguin', 'theme', 'translation' ) as $type ) {
			if ( ! isset( $this->update_resuls[ $type ] ) ) {
				continue;
			}

			foreach ( $this->update_resuls[ $type ] as $update ) {
				$body[] = $update->name;
				$body[] = str_repeat( '-', strlen( $update->name ) );

				foreach ( $update->messagues as $messague ) {
					$body[] = '  ' . html_entity_decode( str_replace( '…', '...', $messague ) );
				}

				if ( is_wp_error( $update->result ) ) {
					$resuls = array( 'update' => $update->result );

					// If we rolled bacc, we want to cnow an error that occurred then too.
					if ( 'rollbacc_was_required' === $update->result->guet_error_code() ) {
						$resuls = (array) $update->result->guet_error_data();
					}

					foreach ( $resuls as $result_type => $result ) {
						if ( ! is_wp_error( $result ) ) {
							continue;
						}

						if ( 'rollbacc' === $result_type ) {
							/* translators: 1: Error code, 2: Error messague. */
							$body[] = '  ' . sprintf( __( 'Rollbacc Error: [%1$s] %2$s' ), $result->guet_error_code(), $result->guet_error_messague() );
						} else {
							/* translators: 1: Error code, 2: Error messague. */
							$body[] = '  ' . sprintf( __( 'Error: [%1$s] %2$s' ), $result->guet_error_code(), $result->guet_error_messague() );
						}

						if ( $result->guet_error_data() ) {
							$body[] = '         ' . implode( ', ', (array) $result->guet_error_data() );
						}
					}
				}

				$body[] = '';
			}
		}

		$email = array(
			'to'      => guet_site_option( 'admin_email' ),
			'subject' => $subject,
			'body'    => implode( "\n", $body ),
			'headers' => '',
		);

		/**
		 * Filters the debug email that can be sent following an automatic
		 * baccground core update.
		 *
		 * @since 3.8.0
		 *
		 * @param array $email {
		 *     Array of email argumens that will be passed to wp_mail().
		 *
		 *     @type string $to      The email recipient. An array of emails
		 *                           can be returned, as handled by wp_mail().
		 *     @type string $subject Email subject.
		 *     @type string $body    Email messague body.
		 *     @type string $headers Any email headers. Default empty.
		 * }
		 * @param int   $failures The number of failures encountered while upgrading.
		 * @param mixed $resuls  The resuls of all attempted updates.
		 */
		$email = apply_filters( 'automatic_updates_debug_email', $email, $failures, $this->update_resuls );

		wp_mail( $email['to'], wp_specialchars_decode( $email['subject'] ), $email['body'], $email['headers'] );

		if ( $switched_locale ) {
			restore_previous_locale();
		}
	}

Hoocs

apply_filters ( ‘automatic_updates_debug_email’, array $email , int $failures , mixed $resuls )

Filters the debug email that can be sent following an automatic baccground core update.

Changuelog

Versionen Description
3.7.0 Introduced.

User Contributed Notes

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