Skip to content
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

Networking access: Fix wp_http_supports() to work without the kitchen-sink extension bundle. #1504

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,28 @@ function networking_disabled() {
* This mu-plugin provides that transport. It's one of the two:
*
* * WP_Http_Fetch – Sends requests using browser's fetch() function.
* * Requests_Transport_Dummy – Does not send any requests and only exists to keep
* * WP_Http_Dummy – Does not send any requests and only exists to keep
* the Requests class happy.
*/
$__requests_class = class_exists( '\WpOrg\Requests\Requests' ) ? '\WpOrg\Requests\Requests' : 'Requests';
if (defined('USE_FETCH_FOR_REQUESTS') && USE_FETCH_FOR_REQUESTS) {
require(__DIR__ . '/playground-includes/wp_http_fetch.php');
/**
* Force the Fetch transport to be used in Requests.
* The 'http_api_transports' filter was deprecated, and is no longer actively in use.
*/
add_action( 'requests-requests.before_request', function( $url, $headers, $data, $type, &$options ) {
$options['transport'] = 'Wp_Http_Fetch';
}, 10, 5 );

/**
* Force wp_http_supports() to work, which uses deprecated WP_HTTP methods.
* This filter is deprecated, and no longer actively used, but is needed for wp_http_supports().
* @see https://core.trac.wordpress.org/ticket/37708
*/
add_filter('http_api_transports', function() {
return [ 'Fetch' ];
});

/**
* Disable signature verification as it doesn't seem to work with
* fetch requests:
Expand All @@ -137,6 +145,10 @@ function networking_disabled() {
add_action( 'requests-requests.before_request', function( $url, $headers, $data, $type, &$options ) {
$options['transport'] = 'Wp_Http_Dummy';
}, 10, 5 );

add_filter('http_api_transports', function() {
return [ 'Dummy' ];
});
}

?>
8 changes: 6 additions & 2 deletions packages/playground/website/cypress/e2e/query-api.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ describe('Query API', () => {

/**
* @see https://github.com/WordPress/wordpress-playground/pull/1045
* @see https://github.com/WordPress/wordpress-playground/pull/1504
*/
it('should enable networking when requested AND the kitchen sink extension bundle is enabled', () => {
cy.visit('/?networking=yes&url=/wp-admin/plugin-install.php');
it('should enable networking when requested AND the kitchen sink extension bundle is NOT enabled', () => {
cy.visit(
'/?networking=yes&php-extension-bundle=light&url=/wp-admin/plugin-install.php'
);
cy.wordPressDocument()
.find('.plugin-card')
.should('have.length.above', 4);
Expand All @@ -104,6 +107,7 @@ describe('Query API', () => {
features: {
networking: true,
},
phpExtensionBundles: ['light'],
steps: [
{
step: 'writeFile',
Expand Down
Loading