| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Services; |
| 4 |
|
| 5 |
defined('ABSPATH') || exit; |
| 6 |
|
| 7 |
class ForceUpdateGate |
| 8 |
{ |
| 9 |
public static function shouldBlock($forceUpdate, string $installedVersion, string $runningVersion): bool |
| 10 |
{ |
| 11 |
if (!$forceUpdate) return false; |
| 12 |
|
| 13 |
// A newer plugin package must be allowed to boot so it can re-check |
| 14 |
// the remote force-update status and run its migrations. Otherwise the |
| 15 |
// flag set by the old version permanently prevents the update from |
| 16 |
// taking effect even though WordPress reports the plugin as active. |
| 17 |
return version_compare($installedVersion ?: '0.0.0', $runningVersion, '>='); |
| 18 |
} |
| 19 |
|
| 20 |
public static function shouldHonorRemoteFlag( |
| 21 |
$forceUpdate, |
| 22 |
string $runningVersion, |
| 23 |
?string $latestPublishedVersion |
| 24 |
): bool { |
| 25 |
if (!$forceUpdate) return false; |
| 26 |
|
| 27 |
// The version API currently treats versions it does not know about as |
| 28 |
// forced updates. A hotfix newer than the latest published package is |
| 29 |
// not outdated and must not disable itself because it has no download |
| 30 |
// record yet. |
| 31 |
if ($latestPublishedVersion && version_compare($runningVersion, $latestPublishedVersion, '>')) { |
| 32 |
return false; |
| 33 |
} |
| 34 |
|
| 35 |
return true; |
| 36 |
} |
| 37 |
} |
| 38 |
|