Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
prevent wp version updates
  • Loading branch information
bcotrim committed Apr 5, 2025
commit 8d18fb678c151fb59d7b2aedefaa7c81b76198eb
4 changes: 2 additions & 2 deletions src/components/tests/add-site.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe( 'AddSite', () => {
expect( mockCreateSite ).toHaveBeenCalledWith(
'test',
'My WordPress Website',
expect.any( String ),
{ isLatest: true, version: '6.4.0' },
undefined,
false,
expect.any( Function )
Expand Down Expand Up @@ -311,7 +311,7 @@ describe( 'AddSite', () => {
expect( mockCreateSite ).toHaveBeenCalledWith(
'test',
'My WordPress Website',
'6.3.3',
{ isLatest: false, version: '6.3.3' },
undefined,
false,
expect.any( Function )
Expand Down
17 changes: 16 additions & 1 deletion src/hooks/tests/use-add-site.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ jest.mock( 'src/lib/get-ipc-api', () => ( {
} ),
} ) );

jest.mock( 'src/stores/wordpress-versions-api', () => ( {
useGetWordPressVersions: jest.fn().mockReturnValue( {
data: [
{
version: '6.1.7',
isLatest: true,
},
{
version: '6.2.0',
isLatest: false,
},
],
} ),
} ) );

describe( 'useAddSite', () => {
const mockCreateSite = jest.fn();
const mockUpdateSite = jest.fn();
Expand Down Expand Up @@ -101,7 +116,7 @@ describe( 'useAddSite', () => {
expect( mockCreateSite ).toHaveBeenCalledWith(
'/test/path',
'',
'6.1.7',
{ isLatest: false, version: '6.1.7' },
undefined,
false,
expect.any( Function )
Expand Down
12 changes: 5 additions & 7 deletions src/hooks/use-add-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { useImportExport } from 'src/hooks/use-import-export';
import { useSiteDetails } from 'src/hooks/use-site-details';
import { generateCustomDomainFromSiteName, getDomainNameValidationError } from 'src/lib/domains';
import { getIpcApi } from 'src/lib/get-ipc-api';
import { useRootSelector } from 'src/stores';
import { wordpressVersionsSelectors } from 'src/stores/wordpress-versions-slice';
import { useGetWordPressVersions } from 'src/stores/wordpress-versions-api';
import {
DEFAULT_PHP_VERSION,
DEFAULT_WORDPRESS_VERSION,
Expand All @@ -32,9 +31,8 @@ export function useAddSite() {
const [ customDomainError, setCustomDomainError ] = useState( '' );
const [ existingDomainNames, setExistingDomainNames ] = useState< string[] >( [] );
const [ enableHttps, setEnableHttps ] = useState( false );
const latestStableWpVersion = useRootSelector(
wordpressVersionsSelectors.selectLatestStableVersion
);
const { data: wordpressVersions = [] } = useGetWordPressVersions();
const latestStableVersion = wordpressVersions.find( ( version ) => version.isLatest );

const loadAllCustomDomains = useCallback( () => {
getIpcApi()
Expand Down Expand Up @@ -105,7 +103,7 @@ export function useAddSite() {
await createSite(
path,
siteName ?? '',
{ version: wpVersion, isLatest: wpVersion === latestStableWpVersion?.value },
{ version: wpVersion, isLatest: wpVersion === latestStableVersion?.value },
usedCustomDomain,
useCustomDomain ? enableHttps : false,
async ( newSite ) => {
Expand Down Expand Up @@ -169,7 +167,7 @@ export function useAddSite() {
customDomain,
useCustomDomain,
enableHttps,
latestStableWpVersion,
latestStableVersion,
] );

const handleSiteNameChange = useCallback(
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-site-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ export function SiteDetailsProvider( { children }: SiteDetailsProviderProps ) {
}, [ data ] );

const addMuPlugin = useCallback( async ( siteId: string, pluginFileName: string ) => {
await await getIpcApi().addMuPlugin( siteId, pluginFileName );
await getIpcApi().addMuPlugin( siteId, pluginFileName );
}, [] );

const removeMuPlugin = useCallback( async ( siteId: string, pluginFileName: string ) => {
Expand Down
17 changes: 10 additions & 7 deletions src/modules/site-settings/edit-site-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,6 @@ export default function EditSiteDetails( { currentWpVersion, onSave }: EditSiteD
if ( result.exitCode !== 0 ) {
throw new Error( result.stderr );
}

// Handle the mu-plugin based on the selected version
if ( selectedWpVersion !== latestStableVersion?.value ) {
await addMuPlugin( selectedSite.id, STUDIO_DISABLE_WP_AUTO_UPDATES_PLUGIN );
} else {
await removeMuPlugin( selectedSite.id, STUDIO_DISABLE_WP_AUTO_UPDATES_PLUGIN );
}
} catch ( wpError ) {
console.error( 'Error changing WordPress version:', wpError );
const errorMessage = stripAnsi( ( wpError as Error )?.message );
Expand All @@ -159,6 +152,16 @@ export default function EditSiteDetails( { currentWpVersion, onSave }: EditSiteD
setIsEditingSite( false );
return;
}

try {
if ( selectedWpVersion !== latestStableVersion?.value ) {
await addMuPlugin( selectedSite.id, STUDIO_DISABLE_WP_AUTO_UPDATES_PLUGIN );
} else {
await removeMuPlugin( selectedSite.id, STUDIO_DISABLE_WP_AUTO_UPDATES_PLUGIN );
}
} catch ( e ) {
console.error( 'Error adding or removing mu-plugin:', e );
}
}

// Determine custom domain setting
Expand Down