-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use feature hooks class for managing the hooks
- Loading branch information
1 parent
bbd4374
commit a1921af
Showing
2 changed files
with
54 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,5 @@ | ||
<?php | ||
|
||
use function NewfoldLabs\WP\Context\getContext; | ||
use function NewfoldLabs\WP\Module\Features\getFeature; | ||
namespace NewfoldLabs\WP\Module\Staging; | ||
|
||
if ( function_exists( 'add_action' ) ) { | ||
|
||
// update as needed based on context | ||
add_filter( | ||
'newfold/features/filter/isEnabled/staging', | ||
function($value) { | ||
if ( 'atomic' === getContext( 'platform' ) ) { | ||
$value = false; | ||
} | ||
return $value; | ||
} | ||
); | ||
|
||
add_action( | ||
'after_setup_theme', | ||
function () { | ||
if ( 'atomic' === getContext( 'platform' ) ) { | ||
$stagingFeature = getFeature('staging'); | ||
if ( $stagingFeature ) { | ||
$stagingFeature->disable(); | ||
} | ||
} | ||
} | ||
); | ||
} | ||
new StagingFeatureHooks(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
namespace NewfoldLabs\WP\Module\Staging; | ||
|
||
use function NewfoldLabs\WP\Context\getContext; | ||
use function NewfoldLabs\WP\Module\Features\disable as disableFeature; | ||
|
||
class StagingFeatureHooks { | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() { | ||
$this->hooks(); | ||
} | ||
|
||
/** | ||
* Add hooks. | ||
*/ | ||
public function hooks() { | ||
|
||
// Filter vale based on context | ||
add_filter( 'newfold/features/filter/isEnabled:staging', array( $this, 'filterValue' ) ); | ||
|
||
// Force disable based on context | ||
add_action( 'newfold/features/action/onEnable:staging', array( $this, 'maybeDisable' ) ); | ||
|
||
// Check if should disable on setup | ||
add_action( 'after_setup_theme', array( $this, 'maybeDisable' ) ); | ||
|
||
} | ||
|
||
// Feature filter based on context | ||
function filterValue( $value ) { | ||
if ( $this->shouldDisable() ) { | ||
$value = false; | ||
} | ||
return $value; | ||
} | ||
|
||
// Maybe disable | ||
function maybeDisable() { | ||
if ( $this->shouldDisable() ) { | ||
disableFeature('staging'); | ||
} | ||
} | ||
|
||
// Context condition for disabling feature | ||
function shouldDisable() { | ||
// check for atomic context | ||
return 'atomic' === getContext( 'platform' ); | ||
} | ||
} |