Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
circlecube committed May 14, 2024
1 parent 978d4ba commit e1da152
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 36 deletions.
4 changes: 2 additions & 2 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace NewfoldLabs\WP\Module\Staging;

require_once( __DIR__ . '/includes/StagingFeature.php' );
require_once __DIR__ . '/includes/StagingFeature.php';

new StagingFeatureHooks();
new StagingFeatureHooks();
3 changes: 1 addition & 2 deletions includes/Staging.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function () {
// add CLI commands
add_action(
'cli_init',
function() {
function () {
\WP_CLI::add_command(
'newfold staging',
'NewfoldLabs\WP\Module\Staging\StagingCLI',
Expand Down Expand Up @@ -445,5 +445,4 @@ protected function runCommand( $command, $args = null ) {

return $response;
}

}
46 changes: 23 additions & 23 deletions includes/StagingFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@

/**
* Child class for a feature
*
*
* Child classes should define a name property as the feature name for all API calls. This name will be used in the registry.
* Child class naming convention is {FeatureName}Feature.
*/
class StagingFeature extends \NewfoldLabs\WP\Module\Features\Feature {
/**
* The feature name.
*
* @var string
*/
protected $name = 'staging';
protected $value = true; // default to on
/**
* The feature name.
*
* @var string
*/
protected $name = 'staging';
protected $value = true; // default to on

/**
* Initialize staging feature
*
*/
public function initialize() {
if ( function_exists( 'add_action' ) ) {
/**
* Initialize staging feature
*
*/
public function initialize() {
if ( function_exists( 'add_action' ) ) {

// Register module
add_action(
'plugins_loaded',
function () {
new Staging( getContainer() );
}
);
}
}
// Register module
add_action(
'plugins_loaded',
function () {
new Staging( getContainer() );
}
);
}
}
}
30 changes: 21 additions & 9 deletions includes/StagingFeatureHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
use function NewfoldLabs\WP\Context\getContext;
use function NewfoldLabs\WP\Module\Features\disable as disableFeature;

/**
* This class adds staging feature hooks.
**/
class StagingFeatureHooks {

/**
Expand All @@ -19,36 +22,45 @@ public function __construct() {
* 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
/**
* Feature filter based on context.
*
* @param boolean $value the value
* @return boolean the filtered value
*/
function filterValue( $value ) {
if ( $this->shouldDisable() ) {
$value = false;
}
return $value;
}

// Maybe disable
/**
* Maybe disable the feature.
*
* @return void
*/
function maybeDisable() {
if ( $this->shouldDisable() ) {
disableFeature('staging');
disableFeature( 'staging' );
}
}

// Context condition for disabling feature
/**
* Context condition for disabling feature.
*
* @return boolean whether the feature should be disabled
*/
function shouldDisable() {
// check for atomic context
return 'atomic' === getContext( 'platform' );
}
}
}

0 comments on commit e1da152

Please sign in to comment.