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

Fix: Networking broken when extra PHP extensions are enabled #1045

Merged
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 @@ -141,6 +141,20 @@ function networking_disabled() {
$__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-replace the default WordPress requests transports with the Fetch transport.
//
// WordPress doesn't provide a way to change the default transports,
// that is Curl and FSockopen. Even with all the `http_api_tranports`
// filter used below, WordPress tests if they are supported and will
// use them if their `::test()` method returns true – which it does
// when PHP.wasm runs with the openssl extension loaded.
//
// @see https://github.com/WordPress/wordpress-playground/pull/1045
$reflection = new ReflectionClass($__requests_class);
$property = $reflection->getProperty('transports');
$property->setAccessible(true);
$property->setValue(['Fetch' => 'Wp_Http_Fetch']);

$__requests_class::add_transport('Wp_Http_Fetch');

/**
Expand All @@ -164,9 +178,10 @@ function networking_disabled() {
return [];
});

add_filter('http_request_host_is_external', function ($arg) {
return true;
});
// add_filter('http_request_host_is_external', function ($arg) {
// return true;
// });
add_filter('http_request_host_is_external', '__return_true');
} else {
require(__DIR__ . '/playground-includes/wp_http_dummy.php');
$__requests_class::add_transport('Wp_Http_Dummy');
Expand Down
12 changes: 12 additions & 0 deletions packages/playground/website/cypress/e2e/query-api.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ describe('Query API', () => {
.should('have.length.above', 4);
});

/**
* @see https://github.com/WordPress/wordpress-playground/pull/1045
*/
it('should enable networking when requested AND the kitchen sink extension bundle is enabled', () => {
cy.visit(
'/?php-extension-bundle=kitchen-sink&networking=yes&url=/wp-admin/plugin-install.php'
);
cy.wordPressDocument()
.find('.plugin-card')
.should('have.length.above', 4);
});

/**
* @see https://github.com/WordPress/wordpress-playground/pull/819
* @TODO: Turn this into a unit test once WordPress modules are available
Expand Down
Loading