Skip to content

Commit

Permalink
Merge pull request #6 from newfold-labs/add/feature-register-filter
Browse files Browse the repository at this point in the history
Add/feature register filter
  • Loading branch information
circlecube authored May 21, 2024
2 parents 5e3a792 + 5d3a47d commit e2eb884
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions includes/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ private function __construct() {
*/
public static function initFeatures() {
// Find extended instances of the Feature class and add to the Registry
foreach ( get_declared_classes() as $class ) {
if ( is_subclass_of( $class, 'NewfoldLabs\WP\Module\Features\Feature' ) ) {
// error_log( 'NewfoldLabs\WP\Module\Features child class found: '.$class );
$features = apply_filters( 'newfold/features/filter/register', array() );
foreach ( $features as $feature ) {
// Validate that the feature extends this
if ( is_subclass_of( $feature, 'NewfoldLabs\WP\Module\Features\Feature' ) ) {
// add class to registry and instantiate
self::$registry->set( $class );
self::$registry->set( $feature );
}
}
}
Expand Down Expand Up @@ -147,12 +148,16 @@ public static function getInstance() {
}

/**
* Get Features
* Get All Features and filter states
*
* @return Array list of features and enabled states (key:name value:enabled)
*/
public static function getFeatures() {
return self::$registry->all();
$features = array();
foreach ( self::getFeatureList() as $feature ) {
$features[ $feature ] = Features::getInstance()->getFeature( $feature )->isEnabled();
}
return $features;
}

/**
Expand Down

0 comments on commit e2eb884

Please sign in to comment.