| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong |
| 4 |
namespace Yoast\WP\SEO\Editors\Framework; |
| 5 |
|
| 6 |
use Yoast\WP\SEO\Editors\Domain\Analysis_Features\Analysis_Feature_Interface; |
| 7 |
use Yoast\WP\SEO\Helpers\Language_Helper; |
| 8 |
use Yoast\WP\SEO\Helpers\Options_Helper; |
| 9 |
use Yoast\WP\SEO\Helpers\Product_Helper; |
| 10 |
|
| 11 |
/** |
| 12 |
* Describes the inclusive language analysis feature. |
| 13 |
*/ |
| 14 |
class Inclusive_Language_Analysis implements Analysis_Feature_Interface { |
| 15 |
|
| 16 |
public const NAME = 'inclusiveLanguageAnalysis'; |
| 17 |
|
| 18 |
/** |
| 19 |
* The options helper. |
| 20 |
* |
| 21 |
* @var Options_Helper |
| 22 |
*/ |
| 23 |
private $options_helper; |
| 24 |
|
| 25 |
/** |
| 26 |
* The language helper. |
| 27 |
* |
| 28 |
* @var Language_Helper |
| 29 |
*/ |
| 30 |
private $language_helper; |
| 31 |
|
| 32 |
/** |
| 33 |
* The product helper. |
| 34 |
* |
| 35 |
* @var Product_Helper |
| 36 |
*/ |
| 37 |
private $product_helper; |
| 38 |
|
| 39 |
/** |
| 40 |
* The constructor. |
| 41 |
* |
| 42 |
* @param Options_Helper $options_helper The options helper. |
| 43 |
* @param Language_Helper $language_helper The language helper. |
| 44 |
* @param Product_Helper $product_helper The product helper. |
| 45 |
*/ |
| 46 |
public function __construct( |
| 47 |
Options_Helper $options_helper, |
| 48 |
Language_Helper $language_helper, |
| 49 |
Product_Helper $product_helper |
| 50 |
) { |
| 51 |
$this->options_helper = $options_helper; |
| 52 |
$this->language_helper = $language_helper; |
| 53 |
$this->product_helper = $product_helper; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* If this analysis is enabled. |
| 58 |
* |
| 59 |
* @return bool If this analysis is enabled. |
| 60 |
*/ |
| 61 |
public function is_enabled(): bool { |
| 62 |
return $this->is_globally_enabled() && $this->is_user_enabled() && $this->is_current_version_supported() |
| 63 |
&& $this->language_helper->has_inclusive_language_support( $this->language_helper->get_language() ); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* If this analysis is enabled by the user. |
| 68 |
* |
| 69 |
* @return bool If this analysis is enabled by the user. |
| 70 |
*/ |
| 71 |
private function is_user_enabled(): bool { |
| 72 |
return ! \get_user_meta( \get_current_user_id(), 'wpseo_inclusive_language_analysis_disable', true ); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* If this analysis is enabled globally. |
| 77 |
* |
| 78 |
* @return bool If this analysis is enabled globally. |
| 79 |
*/ |
| 80 |
private function is_globally_enabled(): bool { |
| 81 |
return (bool) $this->options_helper->get( 'inclusive_language_analysis_active', false ); |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* If the inclusive language analysis should be loaded in Free. |
| 86 |
* |
| 87 |
* It should always be loaded when Premium is not active. If Premium is active, it depends on the version. Some |
| 88 |
* Premium versions also have inclusive language code (when it was still a Premium only feature) which would result |
| 89 |
* in rendering the analysis twice. In those cases, the analysis should be only loaded from the Premium side. |
| 90 |
* |
| 91 |
* @return bool If the inclusive language analysis should be loaded. |
| 92 |
*/ |
| 93 |
private function is_current_version_supported(): bool { |
| 94 |
$is_premium = $this->product_helper->is_premium(); |
| 95 |
$premium_version = $this->product_helper->get_premium_version(); |
| 96 |
|
| 97 |
return ! $is_premium |
| 98 |
|| \version_compare( $premium_version, '19.6-RC0', '>=' ) |
| 99 |
|| \version_compare( $premium_version, '19.2', '==' ); |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Gets the name. |
| 104 |
* |
| 105 |
* @return string The name. |
| 106 |
*/ |
| 107 |
public function get_name(): string { |
| 108 |
return self::NAME; |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Gets the legacy key. |
| 113 |
* |
| 114 |
* @return string The legacy key. |
| 115 |
*/ |
| 116 |
public function get_legacy_key(): string { |
| 117 |
return 'inclusiveLanguageAnalysisActive'; |
| 118 |
} |
| 119 |
} |
| 120 |
|