Skip to content
This repository has been archived by the owner on May 29, 2020. It is now read-only.

Populate site health screen with auto-updates informations #15

Closed
NicolasKulka opened this issue Feb 27, 2020 · 0 comments · Fixed by #24
Closed

Populate site health screen with auto-updates informations #15

NicolasKulka opened this issue Feb 27, 2020 · 0 comments · Fixed by #24
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@NicolasKulka
Copy link

<?php
add_filter( 'debug_information', 'add_auto_update_plugins_debug_information' );
function add_auto_update_plugins_debug_information( $info ) {

	$wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() );

	// List all available plugins.
	$plugins        = get_plugins();
	$plugin_updates = get_plugin_updates();

	foreach ( $plugins as $plugin_path => $plugin ) {
		$plugin_part = ( is_plugin_active( $plugin_path ) ) ? 'wp-plugins-active' : 'wp-plugins-inactive';

		$plugin_version = $plugin['Version'];
		$plugin_author  = $plugin['Author'];

		$plugin_version_string       = __( 'No version or author information is available.' );
		$plugin_version_string_debug = 'author: (undefined), version: (undefined)';

		if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) {
			// translators: 1: Plugin version number. 2: Plugin author name.
			$plugin_version_string       = sprintf( __( 'Version %1$s by %2$s' ), $plugin_version, $plugin_author );
			$plugin_version_string_debug = sprintf( 'version: %s, author: %s', $plugin_version, $plugin_author );
		} else {
			if ( ! empty( $plugin_author ) ) {
				// translators: %s: Plugin author name.
				$plugin_version_string       = sprintf( __( 'By %s' ), $plugin_author );
				$plugin_version_string_debug = sprintf( 'author: %s, version: (undefined)', $plugin_author );
			}

			if ( ! empty( $plugin_version ) ) {
				// translators: %s: Plugin version number.
				$plugin_version_string       = sprintf( __( 'Version %s' ), $plugin_version );
				$plugin_version_string_debug = sprintf( 'author: (undefined), version: %s', $plugin_version );
			}
		}

		if ( array_key_exists( $plugin_path, $plugin_updates ) ) {
			// translators: %s: Latest plugin version number.
			$plugin_version_string       .= ' ' . sprintf( __( '(Latest version: %s)' ), $plugin_updates[ $plugin_path ]->update->new_version );
			$plugin_version_string_debug .= sprintf( ' (latest version: %s)', $plugin_updates[ $plugin_path ]->update->new_version );
		}

		if ( in_array( $plugin_path, $wp_auto_update_plugins ) ) {
			$plugin_version_string       .= ' ' . sprintf( __( '(Automatic updates: %s)' ), __( 'Enable' ) );
			$plugin_version_string_debug .= sprintf( ' (Automatic updates: %s)', __( 'Enable' ) );
		} else {
			$plugin_version_string       .= ' ' . sprintf( __( '(Automatic updates: %s)' ), __( 'Disable' ) );
			$plugin_version_string_debug .= sprintf( ' (Automatic updates: %s)', __( 'Disable' ) );
		}

		$info[ $plugin_part ]['fields'][ sanitize_text_field( $plugin['Name'] ) ] = array(
			'label' => $plugin['Name'],
			'value' => $plugin_version_string,
			'debug' => $plugin_version_string_debug,
		);
	}

	return $info;
}


add_automatic_updates

@audrasjb audrasjb added this to the 0.2.0 milestone Feb 28, 2020
@audrasjb audrasjb self-assigned this Feb 28, 2020
@audrasjb audrasjb added the enhancement New feature or request label Feb 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants