|
1 | 1 | const { app, BrowserWindow, ipcMain, dialog, Tray, nativeImage, Menu } = require('electron'); |
2 | 2 | const path = require('path'); |
3 | 3 | const fs = require('fs'); |
4 | | -const { exec } = require('child_process'); |
| 4 | +const { exec, execFile } = require('child_process'); |
5 | 5 |
|
6 | 6 | let mainWindow = null; |
7 | 7 | let tray = null; |
@@ -276,7 +276,8 @@ ipcMain.handle('get-function-definitions', async (event, wpDirectory) => { |
276 | 276 | // Create a PHP script to extract function definitions |
277 | 277 | const tempFile = path.join(wpDirectory, 'wp-shell-definitions.php'); |
278 | 278 |
|
279 | | - const wpLoadPath = path.join(wpDirectory, 'wp-load.php').replace(/\\/g, '/'); |
| 279 | + // Normalize path for PHP (always use forward slashes) |
| 280 | + const wpLoadPath = path.join(wpDirectory, 'wp-load.php').split(path.sep).join('/'); |
280 | 281 |
|
281 | 282 | const definitionsScript = `<?php |
282 | 283 | define('WP_USE_THEMES', false); |
@@ -339,10 +340,12 @@ foreach ($userFunctions as $functionName) { |
339 | 340 | } |
340 | 341 |
|
341 | 342 | // Get common PHP functions with their signatures |
| 343 | +// Pattern to match commonly used PHP function prefixes |
| 344 | +\$phpFunctionPattern = '/^(str|array|file|is_|print|echo|var_|json_|serialize|unserialize|count|empty|isset|in_array|explode|implode|trim|sprintf|date|time|preg_)/'; |
| 345 | +
|
342 | 346 | foreach ($allFunctions['internal'] as $functionName) { |
343 | 347 | // Only include commonly used PHP functions to avoid overwhelming the editor |
344 | | - // We'll include all string, array, file, and common utility functions |
345 | | - if (preg_match('/^(str|array|file|is_|print|echo|var_|json_|serialize|unserialize|count|empty|isset|in_array|explode|implode|trim|sprintf|date|time|preg_)/', $functionName)) { |
| 348 | + if (preg_match(\$phpFunctionPattern, $functionName)) { |
346 | 349 | try { |
347 | 350 | $reflection = new ReflectionFunction($functionName); |
348 | 351 | $params = []; |
@@ -376,7 +379,7 @@ echo json_encode([ |
376 | 379 | await fs.promises.writeFile(tempFile, definitionsScript); |
377 | 380 |
|
378 | 381 | return new Promise((resolve, reject) => { |
379 | | - exec(\`php \${tempFile}\`, { |
| 382 | + execFile('php', [tempFile], { |
380 | 383 | cwd: wpDirectory, |
381 | 384 | maxBuffer: 50 * 1024 * 1024, // 50MB buffer for large function lists |
382 | 385 | timeout: 60000, // 60 second timeout |
|
0 commit comments