Skip to content

Commit 0bd0a0e

Browse files
authored
Boost + wpcomsh: ensure API endpoints are registered (#43262)
1 parent 794a2f7 commit 0bd0a0e

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Ensure wpcomsh users are able to purchase the Boost paid offering

projects/plugins/wpcomsh/class-jetpack-plugin-compatibility.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,12 @@ protected function __construct() {
204204
add_filter(
205205
'jetpack_my_jetpack_should_initialize',
206206
function () {
207-
return get_option( 'wpcom_admin_interface' ) === 'wp-admin';
207+
$should_init = get_option( 'wpcom_admin_interface' ) === 'wp-admin';
208+
if ( ! $should_init && class_exists( '\Automattic\Jetpack\My_Jetpack\Initializer' ) ) {
209+
// My Jetpack REST API endpoints are used for more than just My Jetpack UI.
210+
add_action( 'rest_api_init', array( '\Automattic\Jetpack\My_Jetpack\Initializer', 'register_rest_endpoints' ) ); // @phan-suppress-current-line PhanUndeclaredClassInCallable
211+
}
212+
return $should_init;
208213
}
209214
);
210215
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Jetpack Compatibility Test file.
4+
*
5+
* @package wpcomsh
6+
*/
7+
8+
/**
9+
* Test Jetpack_Compatibility functionality.
10+
*/
11+
class JetpackCompatibilityTest extends WP_UnitTestCase {
12+
use \Automattic\Jetpack\PHPUnit\WP_UnitTestCase_Fix;
13+
14+
/**
15+
* Test_wpcomsh_get_plugin_updated_submenus.
16+
*/
17+
public function test_wpcomsh_my_jetpack_rest_apis_available() {
18+
// Check if the REST API routes are registered if Boost is included.
19+
$plugins = getenv( 'JP_MONO_INTEGRATION_PLUGINS' );
20+
if ( ! $plugins || strpos( $plugins, 'boost' ) === false ) {
21+
$this->markTestSkipped( 'Jetpack Boost plugin is not included in JP_MONO_INTEGRATION_PLUGINS.' );
22+
}
23+
24+
$routes = rest_get_server()->get_routes();
25+
26+
$this->assertArrayHasKey( '/my-jetpack/v1/site/products', $routes, 'Products endpoint is not registered' );
27+
}
28+
}

0 commit comments

Comments
 (0)