PluginProbe ʕ •ᴥ•ʔ
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.7
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.7
27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 19.1 19.10 19.11 19.12 19.13 19.14 19.2 19.3 19.4 19.5 19.5.1 19.6 19.6.1 19.7 19.7.1 19.7.2 19.8 19.9 20.0 20.1 20.10 20.11 20.12 20.13 20.2 20.2.1 20.3 20.4 20.5 20.6 20.7 20.8 20.9 21.0 21.1 21.2 21.3 21.4 21.5 21.6 21.7 21.8 21.8.1 21.9 21.9.1 22.0 22.1 22.2 22.3 22.4 22.5 22.6 22.7 22.8 22.9 23.0 23.1 23.2 23.3 23.4 23.5 23.6 23.7 23.8 23.9 24.0 24.1 24.2 24.3 24.4 24.5 24.6 24.7 24.8 24.8.1 24.9 25.0 25.1 25.2 25.3 25.3.1 25.4 25.5 25.6 25.7 25.8 25.9 26.0 26.1 26.1.1 26.2 26.3 26.4 26.5 26.6 26.7 26.8 26.9 27.0 27.1 27.1.1 27.2 27.3 27.4
wordpress-seo / src / integrations / feature-flag-integration.php
wordpress-seo / src / integrations Last commit date
admin 3 weeks ago alerts 9 months ago blocks 4 weeks ago front-end 3 months ago third-party 3 months ago watchers 3 months ago abstract-exclude-post-type.php 1 year ago academy-integration.php 3 weeks ago breadcrumbs-integration.php 2 years ago cleanup-integration.php 3 months ago estimated-reading-time.php 5 years ago exclude-attachment-post-type.php 3 years ago exclude-oembed-cache-post-type.php 1 year ago feature-flag-integration.php 4 years ago front-end-integration.php 1 month ago integration-interface.php 5 years ago primary-category.php 5 years ago settings-integration.php 2 months ago support-integration.php 6 months ago uninstall-integration.php 4 years ago woocommerce-product-category-permalink-integration.php 3 months ago xmlrpc.php 4 years ago
feature-flag-integration.php
107 lines
1 <?php
2
3 namespace Yoast\WP\SEO\Integrations;
4
5 use WPSEO_Admin_Asset_Manager;
6 use Yoast\WP\SEO\Conditionals\Admin_Conditional;
7 use Yoast\WP\SEO\Conditionals\Feature_Flag_Conditional;
8
9 /**
10 * Gathers all feature flags and surfaces them to the JavaScript side of the plugin.
11 */
12 class Feature_Flag_Integration implements Integration_Interface {
13
14 /**
15 * The admin asset manager.
16 *
17 * @var WPSEO_Admin_Asset_Manager
18 */
19 protected $asset_manager;
20
21 /**
22 * All of the feature flag conditionals.
23 *
24 * @var Feature_Flag_Conditional[]
25 */
26 protected $feature_flags;
27
28 /**
29 * Feature_Flag_Integration constructor.
30 *
31 * @param WPSEO_Admin_Asset_Manager $asset_manager The admin asset manager.
32 * @param Feature_Flag_Conditional ...$feature_flags All of the known feature flag conditionals.
33 */
34 public function __construct( WPSEO_Admin_Asset_Manager $asset_manager, Feature_Flag_Conditional ...$feature_flags ) {
35 $this->asset_manager = $asset_manager;
36 $this->feature_flags = $feature_flags;
37 }
38
39 /**
40 * Returns the conditionals based on which this loadable should be active.
41 *
42 * @return string[] The conditionals based on which this loadable should be active.
43 */
44 public static function get_conditionals() {
45 return [ Admin_Conditional::class ];
46 }
47
48 /**
49 * Initializes the integration.
50 *
51 * @return void
52 */
53 public function register_hooks() {
54 \add_action( 'admin_init', [ $this, 'add_feature_flags' ] );
55 }
56
57 /**
58 * Gathers all the feature flags and injects them into the JavaScript.
59 *
60 * @return void
61 */
62 public function add_feature_flags() {
63 $enabled_features = $this->get_enabled_features();
64 // Localize under both names for BC.
65 $this->asset_manager->localize_script( 'feature-flag-package', 'wpseoFeatureFlags', $enabled_features );
66 $this->asset_manager->localize_script( 'feature-flag-package', 'wpseoFeaturesL10n', $enabled_features );
67 }
68
69 /**
70 * Returns an array of all enabled feature flags.
71 *
72 * @return string[] The array of enabled features.
73 */
74 public function get_enabled_features() {
75 $enabled_features = [];
76 foreach ( $this->feature_flags as $feature_flag ) {
77 if ( $feature_flag->is_met() ) {
78 $enabled_features[] = $feature_flag->get_feature_name();
79 }
80 }
81
82 return $this->filter_enabled_features( $enabled_features );
83 }
84
85 /**
86 * Runs the list of enabled feature flags through a filter.
87 *
88 * @param string[] $enabled_features The list of currently enabled feature flags.
89 *
90 * @return string[] The (possibly adapted) list of enabled features.
91 */
92 protected function filter_enabled_features( $enabled_features ) {
93 /**
94 * Filters the list of currently enabled feature flags.
95 *
96 * @param string[] $enabled_features The current list of enabled feature flags.
97 */
98 $filtered_enabled_features = \apply_filters( 'wpseo_enable_feature', $enabled_features );
99
100 if ( ! \is_array( $filtered_enabled_features ) ) {
101 $filtered_enabled_features = $enabled_features;
102 }
103
104 return $filtered_enabled_features;
105 }
106 }
107