| 1 |
<?php |
| 2 |
defined('ABSPATH') or die('Unauthorized Access'); |
| 3 |
|
| 4 |
class Phpinfo_WP_EOL { |
| 5 |
|
| 6 |
private static function _pro(): bool { return Phpinfo_WP_License::is_valid(); } |
| 7 |
|
| 8 |
// EOL dates from https://www.php.net/supported-versions.php |
| 9 |
/** |
| 10 |
* @var mixed[] |
| 11 |
*/ |
| 12 |
private static $eol = [ |
| 13 |
'5.6' => '2018-12-31', |
| 14 |
'7.0' => '2019-12-03', |
| 15 |
'7.1' => '2019-12-01', |
| 16 |
'7.2' => '2020-11-30', |
| 17 |
'7.3' => '2021-12-06', |
| 18 |
'7.4' => '2022-11-28', |
| 19 |
'8.0' => '2023-11-26', |
| 20 |
'8.1' => '2024-12-31', |
| 21 |
'8.2' => '2026-12-31', |
| 22 |
'8.3' => '2027-12-31', |
| 23 |
'8.4' => '2028-12-31', |
| 24 |
]; |
| 25 |
|
| 26 |
public static function minor(): string { |
| 27 |
preg_match('/^(\d+\.\d+)/', PHP_VERSION, $m); |
| 28 |
return $m[1] ?? ''; |
| 29 |
} |
| 30 |
|
| 31 |
public static function eol_date(string $minor = ''): ?string { |
| 32 |
$minor = $minor ?: self::minor(); |
| 33 |
return self::$eol[$minor] ?? null; |
| 34 |
} |
| 35 |
|
| 36 |
// Returns: ['status' => ok|warning|eol|unknown, 'eol' => date|null, 'days' => int|null] |
| 37 |
public static function status(): array { |
| 38 |
$minor = self::minor(); |
| 39 |
$eol = self::eol_date($minor); |
| 40 |
|
| 41 |
if (!$eol) return ['status' => 'unknown', 'eol' => null, 'days' => null, 'minor' => $minor]; |
| 42 |
|
| 43 |
$days = (int) round((strtotime($eol) - time()) / DAY_IN_SECONDS); |
| 44 |
|
| 45 |
$state = 'ok'; |
| 46 |
if ($days < 0) $state = 'eol'; |
| 47 |
elseif ($days < 90) $state = 'warning'; |
| 48 |
|
| 49 |
return ['status' => $state, 'eol' => $eol, 'days' => $days, 'minor' => $minor]; |
| 50 |
} |
| 51 |
|
| 52 |
// Shown on every admin page — free feature, drives urgency |
| 53 |
public static function admin_notice(): void { |
| 54 |
$s = self::status(); |
| 55 |
if ($s['status'] === 'ok' || $s['status'] === 'unknown') return; |
| 56 |
|
| 57 |
if ($s['status'] === 'eol') { |
| 58 |
$msg = sprintf( |
| 59 |
'PHP %s reached end-of-life on %s and no longer receives security patches. Upgrade immediately.', |
| 60 |
esc_html($s['minor']), esc_html($s['eol']) |
| 61 |
); |
| 62 |
$type = 'error'; |
| 63 |
} else { |
| 64 |
$msg = sprintf( |
| 65 |
'PHP %s reaches end-of-life on %s (%d days). Plan your upgrade now.', |
| 66 |
esc_html($s['minor']), esc_html($s['eol']), $s['days'] |
| 67 |
); |
| 68 |
$type = 'warning'; |
| 69 |
} |
| 70 |
|
| 71 |
printf( |
| 72 |
'<div class="notice notice-%s is-dismissible"><p><strong>phpinfo() WP:</strong> %s</p></div>', |
| 73 |
$type, $msg |
| 74 |
); |
| 75 |
} |
| 76 |
|
| 77 |
// Full EOL timeline table — free feature; drives urgency for Pro upsell |
| 78 |
public static function timeline(): array { |
| 79 |
$now = time(); |
| 80 |
$out = []; |
| 81 |
foreach (self::$eol as $ver => $date) { |
| 82 |
$ts = strtotime($date); |
| 83 |
$days = (int) round(($ts - $now) / DAY_IN_SECONDS); |
| 84 |
$out[] = [ |
| 85 |
'version' => $ver, |
| 86 |
'eol' => $date, |
| 87 |
'days' => $days, |
| 88 |
'status' => $days < 0 ? 'eol' : ($days < 90 ? 'warning' : 'ok'), |
| 89 |
'current' => ($ver === self::minor()), |
| 90 |
]; |
| 91 |
} |
| 92 |
return $out; |
| 93 |
} |
| 94 |
} |
| 95 |
|