Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 6 additions & 7 deletions packages/common/lib/mu-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,12 @@ function getStandardMuPlugins( options: MuPluginOptions ): MuPlugin[] {
muPlugins.push( {
filename: '0-deactivate-jetpack-modules.php',
content: `<?php
// Disable Jetpack Protect 2FA for local auto-login purpose
add_action( 'jetpack_active_modules', 'jetpack_deactivate_modules' );
function jetpack_deactivate_modules( $active ) {
if ( ( $index = array_search('protect', $active, true) ) !== false ) {
unset( $active[ $index ] );
}
return $active;
// Disable Jetpack Protect so local auto-login is not blocked by 2FA.
// Disable Jetpack Stats so local previews and thumbnails do not bump remote site stats.
add_filter( 'jetpack_active_modules', 'studio_deactivate_jetpack_modules' );
function studio_deactivate_jetpack_modules( $active ) {
$disabled_modules = array( 'protect', 'stats' );
return array_values( array_diff( $active, $disabled_modules ) );
}
`,
} );
Expand Down
24 changes: 24 additions & 0 deletions packages/common/lib/tests/mu-plugins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,30 @@ describe( 'writeStudioMuPluginsForNativePhpRuntime', () => {
expect( generatedPlugins ).toContain( '0-enable-auto-updates.php' );
expect( generatedPlugins ).not.toContain( '0-disable-auto-updates.php' );
} );

it( 'should disable Jetpack modules that affect local development', async () => {
await writeStudioMuPluginsForNativePhpRuntime( sitePath, false );

const loaderPath = join(
sitePath,
'wp-content',
'mu-plugins',
STUDIO_LOADER_MU_PLUGIN_FILENAME
);
const loaderContent = await readFile( loaderPath, 'utf8' );
const muPluginsDir = loaderContent.match( /\$studio_mu_plugins_dir = '([^']+)';/ )?.[ 1 ];

expect( muPluginsDir ).toBeTruthy();

const content = await readFile(
join( muPluginsDir as string, '0-deactivate-jetpack-modules.php' ),
'utf8'
);

expect( content ).toContain( "add_filter( 'jetpack_active_modules'" );
expect( content ).toContain( "$disabled_modules = array( 'protect', 'stats' );" );
expect( content ).toContain( 'array_diff( $active, $disabled_modules )' );
} );
} );

describe( 'getMuPlugins error capture', () => {
Expand Down
Loading