feature-flag-conditional.php 821 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * Yoast SEO plugin file.
  4. *
  5. * @package Yoast\YoastSEO\Conditionals
  6. */
  7. namespace Yoast\WP\Free\Conditionals;
  8. /**
  9. * Abstract class for creating conditionals based on feature flags.
  10. */
  11. abstract class Feature_Flag_Conditional implements Conditional {
  12. /**
  13. * Returns whether or not this conditional is met.
  14. *
  15. * @return boolean Whether or not the conditional is met.
  16. */
  17. public function is_met() {
  18. $feature_flag = \strtoupper( $this->get_feature_flag() );
  19. return \defined( 'YOAST_SEO_' . $feature_flag ) && \constant( 'YOAST_SEO_' . $feature_flag ) === true;
  20. }
  21. /**
  22. * Returns the name of the feature flag.
  23. * 'YOAST_SEO_' is automatically prepended to it and it will be uppercased.
  24. *
  25. * @return string the name of the feature flag.
  26. */
  27. abstract protected function get_feature_flag();
  28. }