| 1 |
<?php |
| 2 |
|
| 3 |
// @phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- This namespace should reflect the namespace of the original class. |
| 4 |
namespace Yoast\WP\SEO\Editors\Framework\Integrations; |
| 5 |
|
| 6 |
use Yoast\WP\SEO\Conditionals\Third_Party\Polylang_Conditional; |
| 7 |
use Yoast\WP\SEO\Conditionals\Third_Party\TranslatePress_Conditional; |
| 8 |
use Yoast\WP\SEO\Conditionals\Third_Party\WPML_Conditional; |
| 9 |
use Yoast\WP\SEO\Editors\Domain\Integrations\Integration_Data_Provider_Interface; |
| 10 |
|
| 11 |
/** |
| 12 |
* Describes if the Multilingual integration is enabled. |
| 13 |
*/ |
| 14 |
class Multilingual implements Integration_Data_Provider_Interface { |
| 15 |
|
| 16 |
/** |
| 17 |
* The WPML conditional. |
| 18 |
* |
| 19 |
* @var WPML_Conditional |
| 20 |
*/ |
| 21 |
private $wpml_conditional; |
| 22 |
|
| 23 |
/** |
| 24 |
* The Polylang conditional. |
| 25 |
* |
| 26 |
* @var Polylang_Conditional |
| 27 |
*/ |
| 28 |
private $polylang_conditional; |
| 29 |
|
| 30 |
/** |
| 31 |
* The TranslatePress conditional. |
| 32 |
* |
| 33 |
* @var TranslatePress_Conditional |
| 34 |
*/ |
| 35 |
private $translate_press_conditional; |
| 36 |
|
| 37 |
/** |
| 38 |
* The constructor. |
| 39 |
* |
| 40 |
* @param WPML_Conditional $wpml_conditional The wpml conditional. |
| 41 |
* @param Polylang_Conditional $polylang_conditional The polylang conditional. |
| 42 |
* @param TranslatePress_Conditional $translate_press_conditional The translate press conditional. |
| 43 |
*/ |
| 44 |
public function __construct( WPML_Conditional $wpml_conditional, Polylang_Conditional $polylang_conditional, TranslatePress_Conditional $translate_press_conditional ) { |
| 45 |
$this->wpml_conditional = $wpml_conditional; |
| 46 |
$this->polylang_conditional = $polylang_conditional; |
| 47 |
$this->translate_press_conditional = $translate_press_conditional; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* If the integration is activated. |
| 52 |
* |
| 53 |
* @return bool If the integration is activated. |
| 54 |
*/ |
| 55 |
public function is_enabled(): bool { |
| 56 |
return $this->multilingual_plugin_active(); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Return this object represented by a key value array. |
| 61 |
* |
| 62 |
* @return array<string, bool> Returns the name and if the feature is enabled. |
| 63 |
*/ |
| 64 |
public function to_array(): array { |
| 65 |
return [ 'isMultilingualActive' => $this->is_enabled() ]; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Returns this object represented by a key value structure that is compliant with the script data array. |
| 70 |
* |
| 71 |
* @return array<string, bool> Returns the legacy key and if the feature is enabled. |
| 72 |
*/ |
| 73 |
public function to_legacy_array(): array { |
| 74 |
return [ 'multilingualPluginActive' => $this->is_enabled() ]; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Checks whether a multilingual plugin is currently active. Currently, we only check the following plugins: |
| 79 |
* WPML, Polylang, and TranslatePress. |
| 80 |
* |
| 81 |
* @return bool Whether a multilingual plugin is currently active. |
| 82 |
*/ |
| 83 |
private function multilingual_plugin_active() { |
| 84 |
$wpml_active = $this->wpml_conditional->is_met(); |
| 85 |
$polylang_active = $this->polylang_conditional->is_met(); |
| 86 |
$translatepress_active = $this->translate_press_conditional->is_met(); |
| 87 |
|
| 88 |
return ( $wpml_active || $polylang_active || $translatepress_active ); |
| 89 |
} |
| 90 |
} |
| 91 |
|