HEX
Server: nginx
System: Linux pool195-106-36.bur.atomicsites.net 6.12.57+deb12-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.57-1~bpo12+1 (2025-11-17) x86_64
User: (0)
PHP: 8.3.32
Disabled: pcntl_fork
Upload Files
File: //wordpress/plugins/wp-cloud-client/1.1.7/src/Handler/SiteDetailsHandler.php
<?php

declare(strict_types=1);

namespace VPlugins\WPCloudClient\Handler;

final class SiteDetailsHandler extends AbstractHandler {

	/**
	 * Return the action name.
	 *
	 * @return string Action name.
	 */
	public function action(): string {
		return 'site_details';
	}

	/**
	 * Gather core, plugin, and theme version details.
	 *
	 * @param array<string, mixed> $params Action parameters.
	 * @return array<string, mixed> Site details.
	 */
	public function execute( array $params ): array {
		if ( ! function_exists( 'get_plugins' ) ) {
			require_once ABSPATH . 'wp-admin/includes/plugin.php';
		}
		if ( ! function_exists( 'get_core_updates' ) ) {
			require_once ABSPATH . 'wp-admin/includes/update.php';
		}

		wp_update_plugins();
		wp_version_check();

		$coreCurrentVersion = get_bloginfo( 'version' );
		$coreLatestVersion  = $coreCurrentVersion;
		$coreUpdates        = get_core_updates();

		if ( isset( $coreUpdates[0]->response ) && 'upgrade' === $coreUpdates[0]->response ) {
			$coreLatestVersion = $coreUpdates[0]->current;
		}

		$details = [
			'core_current_version' => $coreCurrentVersion ?: 'NO-CORE-VERSION',
			'core_latest_version'  => $coreLatestVersion ?: 'NO-CORE-VERSION',
		];

		$plugins = $this->getActivePlugins();
		if ( count( $plugins ) > 0 ) {
			$details['plugins'] = $plugins;
		}

		$theme = $this->getCurrentTheme();
		if ( ! empty( $theme ) ) {
			$details['theme'] = $theme;
		}

		return $details;
	}

	/**
	 * Retrieve active plugins with version info.
	 *
	 * @return array<int, array<string, string>> Active plugin list.
	 */
	private function getActivePlugins(): array {
		$pluginUpdates     = $this->getPluginUpdates();
		$activePluginFiles = (array) get_option( 'active_plugins', [] );
		$result            = [];

		foreach ( get_plugins() as $id => $info ) {
			if ( ! in_array( $id, $activePluginFiles, true ) ) {
				continue;
			}

			$pluginName     = dirname( plugin_basename( $id ) );
			$currentVersion = $info['Version'] ?: 'NO-PLUGIN-VERSION';
			$latestVersion  = $currentVersion;

			if ( array_key_exists( $id, $pluginUpdates ) ) {
				$latestVersion = $pluginUpdates[ $id ]->update->new_version;
			}

			$result[] = [
				'id'              => $pluginName,
				'current_version' => $currentVersion,
				'latest_version'  => $latestVersion ?: 'NO-PLUGIN-VERSION',
			];
		}

		return $result;
	}

	/**
	 * Retrieve plugins with available updates.
	 *
	 * @return array<string, object> Plugins with update data.
	 */
	private function getPluginUpdates(): array {
		$allPlugins     = get_plugins();
		$upgradePlugins = [];
		$current        = get_site_transient( 'update_plugins' );

		foreach ( $allPlugins as $pluginFile => $pluginData ) {
			if ( isset( $current->response[ $pluginFile ] ) ) {
				$upgradePlugins[ $pluginFile ]         = (object) $pluginData;
				$upgradePlugins[ $pluginFile ]->update = $current->response[ $pluginFile ];
			}
		}

		return $upgradePlugins;
	}

	/**
	 * Retrieve current theme version details.
	 *
	 * @return array<string, string> Theme info or empty array.
	 */
	private function getCurrentTheme(): array {
		$currentTheme = wp_get_theme();
		if ( ! $currentTheme->exists() ) {
			return [];
		}

		$themeSlug      = $currentTheme->stylesheet;
		$currentVersion = $currentTheme->get( 'Version' );

		$result = [
			'id'              => $themeSlug,
			'current_version' => $currentVersion ?: 'NO-THEME-VERSION',
		];

		$themeUpdates = get_theme_updates();
		if ( array_key_exists( $themeSlug, $themeUpdates ) && isset( $themeUpdates[ $themeSlug ]->update['new_version'] ) ) {
			$result['latest_version'] = $themeUpdates[ $themeSlug ]->update['new_version'];
		} else {
			$result['latest_version'] = $currentVersion;
		}

		$result['latest_version'] = $result['latest_version'] ?: 'NO-THEME-VERSION';

		return $result;
	}
}