-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding feature to disable WordPress directory information #106
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a1af360
Adding scaffolder feature
srtfisher 9eaf6e3
Adding scaffolder feature
srtfisher db7cfae
Adding the scaffold script
srtfisher abab2f7
Improve scaffodler files
srtfisher 7906246
Adding disable_site_health_directories feature
srtfisher 64da6b4
Running fixer
srtfisher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: wp-alleyvate@feature | ||
|
||
inputs: | ||
- name: featureName | ||
description: "Feature Name" | ||
type: string | ||
- name: tests | ||
description: "Include Tests?" | ||
type: boolean | ||
default: true | ||
|
||
files: | ||
- source: feature.php.hbs | ||
destination: src/alley/wp/alleyvate/features/{{ wpClassFilename inputs.featureName }} | ||
- source: test.php.hbs | ||
if: "{{ inputs.tests }}" | ||
destination: tests/alley/wp/alleyvate/features/{{ wpClassFilename inputs.featureName prefix="test-" }} |
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,27 @@ | ||
<?php | ||
/** | ||
* Class file for {{ wpClassName inputs.featureName }} | ||
* | ||
* (c) Alley <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package wp-alleyvate | ||
*/ | ||
|
||
namespace Alley\WP\Alleyvate\Features; | ||
|
||
use Alley\WP\Types\Feature; | ||
|
||
/** | ||
* {{ wpClassName inputs.featureName }} feature. | ||
*/ | ||
final class {{ wpClassName inputs.featureName }} implements Feature { | ||
/** | ||
* Boot the feature. | ||
*/ | ||
public function boot(): void { | ||
// ... | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
/** | ||
* Class file for {{ wpClassName inputs.featureName prefix="Test_" }} | ||
* | ||
* (c) Alley <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package wp-alleyvate | ||
*/ | ||
|
||
declare( strict_types=1 ); | ||
|
||
namespace Alley\WP\Alleyvate\Features; | ||
|
||
use Mantle\Testing\Concerns\Refresh_Database; | ||
use Mantle\Testkit\Test_Case; | ||
|
||
/** | ||
* Tests for {{ wpClassName inputs.featureName }} feature. | ||
*/ | ||
final class {{ wpClassName inputs.featureName prefix="Test_" }} extends Test_Case { | ||
use Refresh_Database; | ||
|
||
/** | ||
* Feature instance. | ||
* | ||
* @var {{ wpClassName inputs.featureName }} | ||
*/ | ||
private {{ wpClassName inputs.featureName }} $feature; | ||
|
||
/** | ||
* Set up. | ||
*/ | ||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->feature = new {{ wpClassName inputs.featureName }}(); | ||
} | ||
|
||
/** | ||
* Example Test. | ||
*/ | ||
public function test_example(): void { | ||
// Activate the feature. | ||
$this->feature->boot(); | ||
|
||
$this->assertTrue( true ); | ||
} | ||
} |
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
62 changes: 62 additions & 0 deletions
62
src/alley/wp/alleyvate/features/class-disable-site-health-directories.php
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,62 @@ | ||
<?php | ||
/** | ||
* Class file for Disable_Site_Health_Directories | ||
* | ||
* (c) Alley <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package wp-alleyvate | ||
*/ | ||
|
||
namespace Alley\WP\Alleyvate\Features; | ||
|
||
use Alley\WP\Types\Feature; | ||
|
||
/** | ||
* Disable_Site_Health_Directories feature. | ||
*/ | ||
final class Disable_Site_Health_Directories implements Feature { | ||
/** | ||
* Boot the feature. | ||
*/ | ||
public function boot(): void { | ||
add_filter( 'rest_pre_dispatch', [ $this, 'filter_rest_pre_dispatch' ], 10, 3 ); | ||
add_filter( 'debug_information', [ $this, 'filter_debug_information' ] ); | ||
} | ||
|
||
/** | ||
* Filter REST API requests to remove Site Health directories. | ||
* | ||
* @param mixed $result Response to replace the requested version with. Can be anything a normal endpoint can return, or null to not hijack the request. | ||
* @param \WP_REST_Server $server Server instance. | ||
* @param \WP_REST_Request $request Request used to generate the response. | ||
* @return mixed Response to replace the requested version with. | ||
*/ | ||
public function filter_rest_pre_dispatch( $result, $server, $request ) { | ||
if ( $request->get_route() === '/wp-site-health/v1/directory-sizes' ) { | ||
return new \WP_Error( 'rest_disabled', 'REST API endpoint disabled.', [ 'status' => 403 ] ); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Filter debug information to remove Site Health directories. | ||
* | ||
* @param array<string, array{label: string, description: string, fields: array<int, mixed>}> $info Debug information. | ||
* @return array<string, array{label: string, description: string, fields: array<int, mixed>}> Debug information. | ||
*/ | ||
public function filter_debug_information( $info ): array { | ||
if ( ! \is_array( $info ) ) { | ||
$info = []; | ||
} | ||
|
||
if ( isset( $info['wp-paths-sizes'] ) ) { | ||
unset( $info['wp-paths-sizes'] ); | ||
} | ||
|
||
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
52 changes: 52 additions & 0 deletions
52
tests/alley/wp/alleyvate/features/test-disable-site-health-directories.php
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 | ||
/** | ||
* Class file for Test_Disable_Site_Health_Directories | ||
* | ||
* (c) Alley <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package wp-alleyvate | ||
*/ | ||
|
||
declare( strict_types=1 ); | ||
|
||
namespace Alley\WP\Alleyvate\Features; | ||
|
||
use Mantle\Testing\Concerns\Refresh_Database; | ||
use Mantle\Testkit\Test_Case; | ||
|
||
/** | ||
* Tests for Disable_Site_Health_Directories feature. | ||
*/ | ||
final class Test_Disable_Site_Health_Directories extends Test_Case { | ||
use Refresh_Database; | ||
|
||
/** | ||
* Feature instance. | ||
* | ||
* @var Disable_Site_Health_Directories | ||
*/ | ||
private Disable_Site_Health_Directories $feature; | ||
|
||
/** | ||
* Set up. | ||
*/ | ||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->feature = new Disable_Site_Health_Directories(); | ||
} | ||
|
||
/** | ||
* Test that the REST API endpoint is disabled. | ||
*/ | ||
public function test_rest_api_disabled(): void { | ||
$this->feature->boot(); | ||
|
||
$this->acting_as( 'administrator' ); | ||
|
||
$this->get( rest_url( 'wp-site-health/v1/directory-sizes' ) )->assertStatus( 403 ); | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scaffolder is so cool 😎