Skip to content

Commit

Permalink
Use a feature class to represent standard feature behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
dlh01 committed Feb 8, 2024
1 parent 600c631 commit 43e3c57
Show file tree
Hide file tree
Showing 24 changed files with 228 additions and 228 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [ 8.0, 8.1, 8.2, 8.3 ]
php: [ 8.1, 8.2, 8.3 ]
wp_version: [ "latest" ]
multisite: [ false, true ]
name: WordPress ${{ matrix.wp_version }} @ PHP ${{ matrix.php }} (WP_MULTISITE=${{ matrix.multisite }})
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@ This library adheres to [Semantic Versioning](https://semver.org/) and [Keep a C

## Unreleased

### Added

* `Alley\WP\Alleyvate\Feature` class implementing the `Alley\WP\Types\Feature` interface.

### Changed

* The minimum PHP version is now 8.1.
* Feature classes now implement the `Alley\WP\Types\Feature` interface instead of `Alley\WP\Alleyvate\Feature`.
* Unit tests: misc changes and fixes.
* Unit tests: the `$feature` property uses the main feature class for better IDE intelephense support.
* Unit tests: all test cases use `declare( strict_types=1 );`.
* Unit tests: added test to confirm the attachment rewrite rules are removed
* Unit tests: support for `convertDeprecationsToExceptions="true"` added. Tests
will fail if there are PHP deprecation warnings.

### Removed

* `site_health`: Removed as a dedicated feature and now implemented directly in the plugin.
* `Alley\WP\Alleyvate\Feature` interface.

## 2.4.0

### Added
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
"composer/installers": true,
"dealerdirect/phpcodesniffer-composer-installer": true
},
"lock": false
"lock": false,
"sort-packages": true
},
"require": {
"php": "^8.0",
"php": "^8.1",
"alleyinteractive/composer-wordpress-autoloader": "^1.0",
"alleyinteractive/wp-type-extensions": "^1.0",
"composer/installers": "^1.0"
},
"require-dev": {
Expand Down
94 changes: 94 additions & 0 deletions src/alley/wp/alleyvate/class-feature.php
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;
}
}
42 changes: 42 additions & 0 deletions src/alley/wp/alleyvate/class-site-health-panel.php
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;
}
}
2 changes: 1 addition & 1 deletion src/alley/wp/alleyvate/features/class-clean-admin-bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Alley\WP\Alleyvate\Features;

use Alley\WP\Alleyvate\Feature;
use Alley\WP\Types\Feature;

/**
* Cleans admin bar.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use WP_Admin_Bar;
use WP_Query;
use Alley\WP\Alleyvate\Feature;
use Alley\WP\Types\Feature;

/**
* Disable attachment routing.
Expand Down
2 changes: 1 addition & 1 deletion src/alley/wp/alleyvate/features/class-disable-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Alley\WP\Alleyvate\Features;

use Alley\WP\Alleyvate\Feature;
use Alley\WP\Types\Feature;

/**
* Fully disables comments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Alley\WP\Alleyvate\Features;

use Alley\WP\Alleyvate\Feature;
use Alley\WP\Types\Feature;

/**
* Disable the custom fields meta box.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Alley\WP\Alleyvate\Features;

use Alley\WP\Alleyvate\Feature;
use Alley\WP\Types\Feature;

/**
* Disable selected unpopular dashboard widgets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Alley\WP\Alleyvate\Features;

use Alley\WP\Alleyvate\Feature;
use Alley\WP\Types\Feature;

/**
* Fully disables password change notifications.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Alley\WP\Alleyvate\Features;

use Alley\WP\Alleyvate\Feature;
use Alley\WP\Types\Feature;

/**
* Fully disables sticky posts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Alley\WP\Alleyvate\Features;

use Alley\WP\Alleyvate\Feature;
use Alley\WP\Types\Feature;

/**
* Fully disables pingbacks and trackbacks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Alley\WP\Alleyvate\Features;

use Alley\WP\Alleyvate\Feature;
use Alley\WP\Types\Feature;

/**
* Disallow theme/plugin editing in the filesystem to safeguard against unexpected code changes.
Expand Down
2 changes: 1 addition & 1 deletion src/alley/wp/alleyvate/features/class-login-nonce.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Alley\WP\Alleyvate\Features;

use Alley\WP\Alleyvate\Feature;
use Alley\WP\Types\Feature;

/**
* Adds a nonce field to the login form.
Expand Down
2 changes: 1 addition & 1 deletion src/alley/wp/alleyvate/features/class-prevent-framing.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Alley\WP\Alleyvate\Features;

use Alley\WP\Alleyvate\Feature;
use Alley\WP\Types\Feature;

/**
* Headers to prevent iframe-ing of the site.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Alley\WP\Alleyvate\Features;

use Alley\WP\Alleyvate\Feature;
use Alley\WP\Types\Feature;

/**
* Disable `redirect_guess_404_permalink()`, whose behavior often confuses clients
Expand Down
60 changes: 0 additions & 60 deletions src/alley/wp/alleyvate/features/class-site-health.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Alley\WP\Alleyvate\Features;

use Alley\WP\Alleyvate\Feature;
use Alley\WP\Types\Feature;
use WP_Error;
use WP_HTTP_Response;
use WP_REST_Request;
Expand Down
23 changes: 0 additions & 23 deletions src/alley/wp/alleyvate/interface-feature.php

This file was deleted.

Loading

0 comments on commit 43e3c57

Please sign in to comment.