WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_Site_Health::get_test_plugin_version() public WP 5.2.0

Test if plugins are outdated, or unnecessary.

The tests checks if your plugins are up to date, and encourages you to remove any that are not in use.

Это метод класса: WP_Site_Health{}

Хуков нет.

Возвращает

Массив. The test result.

Использование

$WP_Site_Health = new WP_Site_Health();
$WP_Site_Health->get_test_plugin_version();

Список изменений

С версии 5.2.0 Введена.

Код WP_Site_Health::get_test_plugin_version() WP 5.5.1

wp-admin/includes/class-wp-site-health.php
<?php
public function get_test_plugin_version() {
	$result = array(
		'label'       => __( 'Your plugins are all up to date' ),
		'status'      => 'good',
		'badge'       => array(
			'label' => __( 'Security' ),
			'color' => 'blue',
		),
		'description' => sprintf(
			'<p>%s</p>',
			__( 'Plugins extend your site&#8217;s functionality with things like contact forms, ecommerce and much more. That means they have deep access to your site, so it&#8217;s vital to keep them up to date.' )
		),
		'actions'     => sprintf(
			'<p><a href="%s">%s</a></p>',
			esc_url( admin_url( 'plugins.php' ) ),
			__( 'Manage your plugins' )
		),
		'test'        => 'plugin_version',
	);

	$plugins        = get_plugins();
	$plugin_updates = get_plugin_updates();

	$plugins_have_updates = false;
	$plugins_active       = 0;
	$plugins_total        = 0;
	$plugins_need_update  = 0;

	// Loop over the available plugins and check their versions and active state.
	foreach ( $plugins as $plugin_path => $plugin ) {
		$plugins_total++;

		if ( is_plugin_active( $plugin_path ) ) {
			$plugins_active++;
		}

		$plugin_version = $plugin['Version'];

		if ( array_key_exists( $plugin_path, $plugin_updates ) ) {
			$plugins_need_update++;
			$plugins_have_updates = true;
		}
	}

	// Add a notice if there are outdated plugins.
	if ( $plugins_need_update > 0 ) {
		$result['status'] = 'critical';

		$result['label'] = __( 'You have plugins waiting to be updated' );

		$result['description'] .= sprintf(
			'<p>%s</p>',
			sprintf(
				/* translators: %d: The number of outdated plugins. */
				_n(
					'Your site has %d plugin waiting to be updated.',
					'Your site has %d plugins waiting to be updated.',
					$plugins_need_update
				),
				$plugins_need_update
			)
		);

		$result['actions'] .= sprintf(
			'<p><a href="%s">%s</a></p>',
			esc_url( network_admin_url( 'plugins.php?plugin_status=upgrade' ) ),
			__( 'Update your plugins' )
		);
	} else {
		if ( 1 === $plugins_active ) {
			$result['description'] .= sprintf(
				'<p>%s</p>',
				__( 'Your site has 1 active plugin, and it is up to date.' )
			);
		} else {
			$result['description'] .= sprintf(
				'<p>%s</p>',
				sprintf(
					/* translators: %d: The number of active plugins. */
					_n(
						'Your site has %d active plugin, and it is up to date.',
						'Your site has %d active plugins, and they are all up to date.',
						$plugins_active
					),
					$plugins_active
				)
			);
		}
	}

	// Check if there are inactive plugins.
	if ( $plugins_total > $plugins_active && ! is_multisite() ) {
		$unused_plugins = $plugins_total - $plugins_active;

		$result['status'] = 'recommended';

		$result['label'] = __( 'You should remove inactive plugins' );

		$result['description'] .= sprintf(
			'<p>%s %s</p>',
			sprintf(
				/* translators: %d: The number of inactive plugins. */
				_n(
					'Your site has %d inactive plugin.',
					'Your site has %d inactive plugins.',
					$unused_plugins
				),
				$unused_plugins
			),
			__( 'Inactive plugins are tempting targets for attackers. If you&#8217;re not going to use a plugin, we recommend you remove it.' )
		);

		$result['actions'] .= sprintf(
			'<p><a href="%s">%s</a></p>',
			esc_url( admin_url( 'plugins.php?plugin_status=inactive' ) ),
			__( 'Manage inactive plugins' )
		);
	}

	return $result;
}