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

Populate site health screen with auto-updates informations #15

@NicolasKulka

Description

@NicolasKulka
<?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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions