Skip to content

Commit

Permalink
Update phpGetThemeDetails to use server process
Browse files Browse the repository at this point in the history
  • Loading branch information
fluiddot committed Apr 24, 2024
1 parent e52bc0e commit 1de5f35
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/ipc-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ export async function getThemeDetails( event: IpcMainInvokeEvent, id: string ) {
if ( ! server.details.running || ! server.server ) {
return null;
}
const themeDetails = await phpGetThemeDetails( server.server.php );
const themeDetails = await phpGetThemeDetails( server.server );

const parentWindow = BrowserWindow.fromWebContents( event.sender );
if ( themeDetails?.path && themeDetails.path !== server.details.themeDetails?.path ) {
Expand Down
18 changes: 10 additions & 8 deletions src/lib/php-get-theme-details.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import * as Sentry from '@sentry/electron/main';
import { WPNowServer } from '../../vendor/wp-now/src';
import SiteServerProcess from './site-server-process';

export async function phpGetThemeDetails(
php: WPNowServer[ 'php' ]
server: SiteServerProcess
): Promise< StartedSiteDetails[ 'themeDetails' ] > {
if ( ! server.php ) {
throw Error( 'PHP is not instantiated' );
}

let themeDetails = null;
const themeDetailsPhp = `<?php
require_once('${ php.documentRoot }/wp-load.php');
require_once('${ server.php.documentRoot }/wp-load.php');
$theme = wp_get_theme();
echo json_encode([
'name' => $theme->get('Name'),
Expand All @@ -19,11 +23,9 @@ export async function phpGetThemeDetails(
]);
`;
try {
themeDetails = (
await php.run( {
code: themeDetailsPhp,
} )
).text;
themeDetails = await server.runPhp( {
code: themeDetailsPhp,
} );
themeDetails = JSON.parse( themeDetails );
} catch ( error ) {
Sentry.captureException( error, {
Expand Down

0 comments on commit 1de5f35

Please sign in to comment.