-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a feature class to represent standard feature behaviors
- Loading branch information
Showing
24 changed files
with
228 additions
and
228 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
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
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
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,94 @@ | ||
<?php | ||
/** | ||
* Class file for Feature | ||
* | ||
* @package wp-alleyvate | ||
*/ | ||
|
||
namespace Alley\WP\Alleyvate; | ||
|
||
/** | ||
* An Alleyvate feature. | ||
*/ | ||
final class Feature implements \Alley\WP\Types\Feature { | ||
/** | ||
* Whether the feature has been booted. | ||
* | ||
* @var bool | ||
*/ | ||
private bool $booted = false; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param string $handle Feature handle. | ||
* @param \Alley\WP\Types\Feature $origin Feature. | ||
*/ | ||
public function __construct( | ||
private string $handle, | ||
private \Alley\WP\Types\Feature $origin, | ||
) {} | ||
|
||
/** | ||
* Boot the feature. | ||
*/ | ||
public function boot(): void { | ||
// Alleyvate features load after all plugins and themes have had a chance to add filters. | ||
add_action( 'after_setup_theme', [ $this, 'filtered_boot' ] ); | ||
add_filter( 'debug_information', [ $this, 'add_debug_information' ] ); | ||
} | ||
|
||
/** | ||
* Boot the origin feature based on filters. | ||
*/ | ||
public function filtered_boot(): void { | ||
$load = true; | ||
|
||
/** | ||
* Filters whether to load an Alleyvate feature. | ||
* | ||
* @param bool $load Whether to load the feature. Default true. | ||
* @param string $handle Feature handle. | ||
*/ | ||
$load = apply_filters( 'alleyvate_load_feature', $load, $this->handle ); | ||
|
||
/** | ||
* Filters whether to load the given Alleyvate feature. | ||
* | ||
* The dynamic portion of the hook name, `$this->$this->handle`, refers to the | ||
* machine name for the feature. | ||
* | ||
* @param bool $load Whether to load the feature. Default true. | ||
*/ | ||
$load = apply_filters( "alleyvate_load_{$this->handle}", $load ); | ||
|
||
if ( $load ) { | ||
$this->booted = true; | ||
$this->origin->boot(); | ||
} | ||
} | ||
|
||
/** | ||
* Add debug information to the Site Health screen. | ||
* | ||
* @param array $info Debug information. | ||
* @return array | ||
*/ | ||
public function add_debug_information( $info ): array { | ||
if ( ! \is_array( $info ) ) { | ||
$info = []; | ||
} | ||
|
||
$info['wp-alleyvate']['fields'] ??= []; | ||
$info['wp-alleyvate']['fields'][] = [ | ||
'label' => sprintf( | ||
/* translators: %s: Feature name. */ | ||
__( 'Feature: %s', 'alley' ), | ||
$this->handle, | ||
), | ||
'value' => $this->booted ? __( 'Enabled', 'alley' ) : __( 'Disabled', 'alley' ), | ||
]; | ||
|
||
return $info; | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
/** | ||
* Site_Health_Panel class file | ||
* | ||
* @package wp-alleyvate | ||
*/ | ||
|
||
namespace Alley\WP\Alleyvate; | ||
|
||
use Alley\WP\Types\Feature; | ||
|
||
/** | ||
* Site Health panel for Alleyvate features. | ||
*/ | ||
final class Site_Health_Panel implements Feature { | ||
/** | ||
* Boot the feature. | ||
*/ | ||
public function boot(): void { | ||
add_filter( 'debug_information', [ $this, 'add_debug_panel' ], 0 ); | ||
} | ||
|
||
/** | ||
* Add debug information for the feature. | ||
* | ||
* @param array $info Debug information. | ||
* @return array | ||
*/ | ||
public function add_debug_panel( $info ): array { | ||
if ( ! \is_array( $info ) ) { | ||
$info = []; | ||
} | ||
|
||
$info['wp-alleyvate'] = [ | ||
'label' => __( 'Alleyvate', 'alley' ), | ||
'description' => __( 'Diagnostic information about the Alleyvate plugin and which features are enabled.', 'alley' ), | ||
'fields' => [], | ||
]; | ||
|
||
return $info; | ||
} | ||
} |
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
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
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
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
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
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
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
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.