Skip to content
Next Next commit
Display the PHP version on Site Settings screen
  • Loading branch information
danielbachhuber committed Jun 9, 2024
commit 7e4bcdbe2bf8c986ca2e4c256aabb8ff824688d5
3 changes: 3 additions & 0 deletions src/components/content-tab-settings.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Icon, file } from '@wordpress/icons';
import { useI18n } from '@wordpress/react-i18n';
import { PropsWithChildren } from 'react';
import { useGetPhpVersion } from '../hooks/use-get-php-version';
import { useGetWpVersion } from '../hooks/use-get-wp-version';
import { getIpcApi } from '../lib/get-ipc-api';
import { decodePassword } from '../lib/passwords';
Expand Down Expand Up @@ -30,6 +31,7 @@ export function ContentTabSettings( { selectedSite }: ContentTabSettingsProps )
// Empty strings account for legacy sites lacking a stored password.
const storedPassword = decodePassword( selectedSite.adminPassword ?? '' );
const password = storedPassword === '' ? 'password' : storedPassword;
const phpVersion = useGetPhpVersion( selectedSite );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the hook useGetPhpVersion is not necessary because the PHP version is already coming from the site details in selectedSite.

	const phpVersion = selectedSite.phpVersion ?? DEFAULT_PHP_VERSION;

Not sure if this approach has been followed based on the other hook useGetWpVersion. If so, the WordPress version needs to be retrieved from the WordPress files as it's not referenced in the site details. That's the main reason for needing that hook.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add these changes in a separate PR to avoid blocking this one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add these changes in a separate PR to avoid blocking this one.

#239

const wpVersion = useGetWpVersion( selectedSite );
return (
<div className="p-8">
Expand Down Expand Up @@ -66,6 +68,7 @@ export function ContentTabSettings( { selectedSite }: ContentTabSettingsProps )
<Icon size={ 13 } icon={ file } className="shrink-0" />
</Button>
</SettingsRow>
<SettingsRow label={ __( 'PHP Version' ) }>{ phpVersion }</SettingsRow>
<SettingsRow label={ __( 'WP Version' ) }>{ wpVersion }</SettingsRow>

<tr>
Expand Down
10 changes: 10 additions & 0 deletions src/hooks/use-get-php-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { useEffect, useState } from 'react';
import { getIpcApi } from '../lib/get-ipc-api';

export function useGetPhpVersion( site: SiteDetails ) {
const [ phpVersion, setPhpVersion ] = useState( '-' );
useEffect( () => {
getIpcApi().getPhpVersion( site.id ).then( setPhpVersion );
}, [ site.id, site.running ] );
return phpVersion;
}
9 changes: 9 additions & 0 deletions src/ipc-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,15 @@ export async function getAppGlobals( _event: IpcMainInvokeEvent ): Promise< AppG
};
}

export async function getPhpVersion( _event: IpcMainInvokeEvent, id: string ) {
const server = SiteServer.get( id );
if ( ! server ) {
return '-';
}
const phpVersion = ( await server.details.phpVersion ) || '-';
return phpVersion;
}

export async function getWpVersion( _event: IpcMainInvokeEvent, id: string ) {
const server = SiteServer.get( id );
if ( ! server ) {
Expand Down
1 change: 1 addition & 0 deletions src/ipc-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface StoppedSiteDetails {
name: string;
path: string;
port?: number;
phpVersion?: string;
adminPassword?: string;
themeDetails?: {
name: string;
Expand Down
1 change: 1 addition & 0 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const api: IpcApi = {
copyText: ( text: string ) => ipcRenderer.invoke( 'copyText', text ),
getAppGlobals: () => ipcRenderer.invoke( 'getAppGlobals' ),
removeTemporalFile: ( path: string ) => ipcRenderer.invoke( 'removeTemporalFile', path ),
getPhpVersion: ( id: string ) => ipcRenderer.invoke( 'getPhpVersion', id ),
getWpVersion: ( id: string ) => ipcRenderer.invoke( 'getWpVersion', id ),
generateProposedSitePath: ( siteName: string ) =>
ipcRenderer.invoke( 'generateProposedSitePath', siteName ),
Expand Down
1 change: 1 addition & 0 deletions src/site-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class SiteServer {
...this.details,
url: this.server.url,
port: this.server.options.port,
phpVersion: options.phpVersion,
running: true,
themeDetails,
};
Expand Down