Skip to content

Commit

Permalink
add staging feature class and move module registration into it
Browse files Browse the repository at this point in the history
  • Loading branch information
circlecube committed Apr 25, 2024
1 parent c464472 commit 46cdb73
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 21 deletions.
27 changes: 6 additions & 21 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
<?php

use NewfoldLabs\WP\ModuleLoader\Container;
use NewfoldLabs\WP\Module\Staging\Staging;
use function NewfoldLabs\WP\ModuleLoader\register;
use function NewfoldLabs\WP\Context\getContext;

if ( function_exists( 'add_action' ) ) {

add_action(
'plugins_loaded',
function () {

register(
array(
'name' => 'staging',
'label' => __( 'Staging', 'newfold-staging-module' ),
'callback' => function ( Container $container ) {
if ( 'atomic' === getContext( 'platform' ) ) {
return;
}
return new Staging( $container );
},
'isActive' => true,
'isHidden' => true,
)
);

'newfold/features/filter/isEnabled/staging',
function($value) {
if ( 'atomic' === getContext( 'platform' ) ) {
$value = false;
}
return $value;
}
);

Expand Down
53 changes: 53 additions & 0 deletions includes/StagingFeature.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace NewfoldLabs\WP\Module\Staging;

use NewfoldLabs\WP\ModuleLoader\Container;
use NewfoldLabs\WP\Module\Staging\Staging;
use function NewfoldLabs\WP\ModuleLoader\register;

/**
* 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

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

add_action(
'plugins_loaded',
function () {

register(
array(
'name' => 'staging',
'label' => __( 'Staging', 'newfold-staging-module' ),
'callback' => function ( Container $container ) {
return new Staging( $container );
},
'isActive' => true,
'isHidden' => true,
)
);

}
);

}
}

}

0 comments on commit 46cdb73

Please sign in to comment.