-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #891 from WordPress/update/can-load-infrastructure
Allow module `can-load.php` callbacks to return a `WP_Error` with more information
- Loading branch information
Showing
9 changed files
with
106 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
/** | ||
* Can load function to determine if Site Health module is supported or not. | ||
* | ||
* @since n.e.x.t | ||
* @package performance-lab | ||
*/ | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; // Exit if accessed directly. | ||
} | ||
|
||
return static function () { | ||
if ( ! has_filter( 'user_has_cap', 'wp_maybe_grant_site_health_caps' ) ) { | ||
return new WP_Error( 'cannot_load_module', esc_html__( 'The module cannot be loaded since the Site Health feature is disabled.', 'performance-lab' ) ); | ||
} else { | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
/** | ||
* Can load function to determine if Site Health module is supported or not. | ||
* | ||
* @since n.e.x.t | ||
* @package performance-lab | ||
*/ | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; // Exit if accessed directly. | ||
} | ||
|
||
return static function () { | ||
if ( ! has_filter( 'user_has_cap', 'wp_maybe_grant_site_health_caps' ) ) { | ||
return new WP_Error( 'cannot_load_module', esc_html__( 'The module cannot be loaded since the Site Health feature is disabled.', 'performance-lab' ) ); | ||
} else { | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
/** | ||
* Can load function to determine if Site Health module is supported or not. | ||
* | ||
* @since n.e.x.t | ||
* @package performance-lab | ||
*/ | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; // Exit if accessed directly. | ||
} | ||
|
||
return static function () { | ||
if ( ! has_filter( 'user_has_cap', 'wp_maybe_grant_site_health_caps' ) ) { | ||
return new WP_Error( 'cannot_load_module', esc_html__( 'The module cannot be loaded since the Site Health feature is disabled.', 'performance-lab' ) ); | ||
} else { | ||
return 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
10 changes: 10 additions & 0 deletions
10
tests/testdata/demo-modules/check-error/demo-module-4/can-load.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,10 @@ | ||
<?php | ||
/** | ||
* Can load function to determine if Site Health module is supported or not. | ||
* | ||
* @package performance-lab | ||
*/ | ||
|
||
return static function () { | ||
return new WP_Error( 'cannot_load_module', esc_html__( 'The module cannot be loaded.', 'performance-lab' ) ); | ||
}; |
10 changes: 10 additions & 0 deletions
10
tests/testdata/demo-modules/check-error/demo-module-4/load.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,10 @@ | ||
<?php | ||
/** | ||
* Module Name: Demo Module 4 | ||
* Description: This is the description for demo module 4. | ||
* Experimental: No | ||
* | ||
* @package performance-lab | ||
*/ | ||
|
||
// This is a demo module and does nothing. |