| 1 |
<?php |
| 2 |
/** |
| 3 |
* Add-ons too old for this Core. |
| 4 |
* |
| 5 |
* Core 5.8 no longer ships the email template routes and the opt-out page |
| 6 |
* generator; the add-ons bring them since email editor 1.1.0 and opt-out |
| 7 |
* 1.4.0 (wordpress.org guideline 5). An older add-on keeps loading without |
| 8 |
* an error, but the email editor shows no templates and "Create opt-out |
| 9 |
* page" answers that the add-on is inactive. This check says why and what |
| 10 |
* to do. |
| 11 |
* |
| 12 |
* @package Forge12\DoubleOptIn\Health |
| 13 |
* @since 5.8.0 |
| 14 |
*/ |
| 15 |
|
| 16 |
declare( strict_types=1 ); |
| 17 |
|
| 18 |
namespace Forge12\DoubleOptIn\Health; |
| 19 |
|
| 20 |
if ( ! defined( 'ABSPATH' ) ) { |
| 21 |
exit; |
| 22 |
} |
| 23 |
|
| 24 |
final class AddonCompatibilityCheck implements HealthCheckInterface { |
| 25 |
|
| 26 |
/** |
| 27 |
* Add-on version constant => [display name, minimum version, what breaks]. |
| 28 |
* |
| 29 |
* @return array<string, array{0: string, 1: string}> |
| 30 |
*/ |
| 31 |
private static function requirements(): array { |
| 32 |
return array( |
| 33 |
'F12_DOI_EMAIL_EDITOR_VERSION' => array( __( 'Email Editor', 'double-opt-in' ), '1.1.0' ), |
| 34 |
'F12_DOI_OPT_OUT_VERSION' => array( __( 'Opt-Out', 'double-opt-in' ), '1.4.0' ), |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
/** @var callable(string):?string */ |
| 39 |
private $versionOf; |
| 40 |
|
| 41 |
/** |
| 42 |
* @param callable|null $versionOf Returns the value of a version constant, |
| 43 |
* or null when the add-on is not loaded (test seam). |
| 44 |
*/ |
| 45 |
public function __construct( ?callable $versionOf = null ) { |
| 46 |
$this->versionOf = $versionOf ?? static function ( string $constant ): ?string { |
| 47 |
return defined( $constant ) ? (string) constant( $constant ) : null; |
| 48 |
}; |
| 49 |
} |
| 50 |
|
| 51 |
public function getId(): string { |
| 52 |
return 'f12_doi_addon_compatibility'; |
| 53 |
} |
| 54 |
|
| 55 |
public function getLabel(): string { |
| 56 |
return __( 'Double Opt-In add-on versions', 'double-opt-in' ); |
| 57 |
} |
| 58 |
|
| 59 |
public function getPackage(): string { |
| 60 |
return 'core'; |
| 61 |
} |
| 62 |
|
| 63 |
public function run(): HealthCheckResult { |
| 64 |
$outdated = array(); |
| 65 |
foreach ( self::requirements() as $constant => $requirement ) { |
| 66 |
$installed = call_user_func( $this->versionOf, $constant ); |
| 67 |
if ( $installed !== null && version_compare( $installed, $requirement[1], '<' ) ) { |
| 68 |
$outdated[] = sprintf( |
| 69 |
/* translators: 1: add-on name, 2: installed version, 3: required version */ |
| 70 |
__( '%1$s %2$s (needs %3$s)', 'double-opt-in' ), |
| 71 |
$requirement[0], |
| 72 |
$installed, |
| 73 |
$requirement[1] |
| 74 |
); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
if ( $outdated === array() ) { |
| 79 |
return new HealthCheckResult( |
| 80 |
HealthCheckResult::STATUS_GOOD, |
| 81 |
__( 'Double Opt-In add-ons match this version', 'double-opt-in' ), |
| 82 |
'', |
| 83 |
'ok' |
| 84 |
); |
| 85 |
} |
| 86 |
|
| 87 |
return new HealthCheckResult( |
| 88 |
HealthCheckResult::STATUS_RECOMMENDED, |
| 89 |
__( 'Update the Double Opt-In add-ons', 'double-opt-in' ), |
| 90 |
sprintf( |
| 91 |
/* translators: %s: comma-separated list of add-ons with versions */ |
| 92 |
__( 'These add-ons are older than this version of Double Opt-In expects: %s. Until they are updated, the email editor shows no templates and "Create opt-out page" does not work. Your templates, settings and opt-ins are not affected.', 'double-opt-in' ), |
| 93 |
implode( ', ', $outdated ) |
| 94 |
), |
| 95 |
'outdated:' . count( $outdated ), |
| 96 |
__( 'Go to updates', 'double-opt-in' ), |
| 97 |
admin_url( 'update-core.php' ) |
| 98 |
); |
| 99 |
} |
| 100 |
} |
| 101 |
|