| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Config; |
| 4 |
|
| 5 |
/** |
| 6 |
* Class Badge_Group_Names. |
| 7 |
* |
| 8 |
* This class defines groups for "new" badges, with the version in which those groups are no longer considered |
| 9 |
* to be "new". |
| 10 |
*/ |
| 11 |
class Badge_Group_Names { |
| 12 |
|
| 13 |
const GROUP_GLOBAL_TEMPLATES = 'global-templates'; |
| 14 |
|
| 15 |
/** |
| 16 |
* Constant describing when certain groups of new badges will no longer be shown. |
| 17 |
*/ |
| 18 |
const GROUP_NAMES = [ |
| 19 |
self::GROUP_GLOBAL_TEMPLATES => '16.7-beta0', |
| 20 |
]; |
| 21 |
|
| 22 |
/** |
| 23 |
* The current plugin version. |
| 24 |
* |
| 25 |
* @var string |
| 26 |
*/ |
| 27 |
protected $version; |
| 28 |
|
| 29 |
/** |
| 30 |
* Badge_Group_Names constructor. |
| 31 |
* |
| 32 |
* @param string|null $version Optional: the current plugin version. |
| 33 |
*/ |
| 34 |
public function __construct( $version = null ) { |
| 35 |
if ( ! $version ) { |
| 36 |
$version = \WPSEO_VERSION; |
| 37 |
} |
| 38 |
$this->version = $version; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Check whether a group of badges is still eligible for a "new" badge. |
| 43 |
* |
| 44 |
* @param string $group One of the GROUP_* constants. |
| 45 |
* @param string|null $current_version The current version of the plugin that's being checked. |
| 46 |
* |
| 47 |
* @return bool Whether a group of badges is still eligible for a "new" badge. |
| 48 |
*/ |
| 49 |
public function is_still_eligible_for_new_badge( $group, $current_version = null ) { |
| 50 |
if ( ! \array_key_exists( $group, $this::GROUP_NAMES ) ) { |
| 51 |
return false; |
| 52 |
} |
| 53 |
|
| 54 |
$group_version = $this::GROUP_NAMES[ $group ]; |
| 55 |
|
| 56 |
if ( \is_null( $current_version ) ) { |
| 57 |
$current_version = $this->version; |
| 58 |
} |
| 59 |
|
| 60 |
return (bool) \version_compare( $group_version, $current_version, '>' ); |
| 61 |
} |
| 62 |
} |
| 63 |
|