-
-
Notifications
You must be signed in to change notification settings - Fork 20
Description
Bug Description
The WordPress Ghost Exporter plugin (v1.6.0) throws a fatal error during activation when upgrading or reactivating the plugin on sites that have previously used it for exports. The error occurs in the deleteLocalExportFiles() method due to an incorrect implementation of array_slice() when cleaning up old export files in the /wp-content/uploads/ghost-exports directory.
Error Message
PHP Fatal error: Uncaught ArgumentCountError: array_slice() expects at least 2 arguments, 1 given in /wp-content/plugins/ghost/class-ghost.php:169Current Implementation (Bug)
$filesInDir = scandir($gfiledir);
$slicesFilesInDir = array_slice($filesInDir); // Missing required offset parameterFixed Implementation
$filesInDir = scandir($gfiledir);
$slicesFilesInDir = array_slice($filesInDir, 2); // Added offset to skip . and .. directoriesSteps to Reproduce
- Have previously used the Ghost exporter plugin (creates /wp-content/uploads/ghost-exports directory)
- Deactivate the plugin
- Install/Update to Ghost WordPress Exporter v1.6.0
- Attempt to activate the plugin
- Plugin fails to activate with the above fatal error
Note: The error only occurs when the /wp-content/uploads/ghost-exports directory exists from previous exports. This is because the deleteLocalExportFiles() method runs during plugin activation to clean up old export files.
Workaround
Until this is fixed, users can either:
- Manually delete the
/wp-content/uploads/ghost-exportsdirectory before activating - Or modify the
deleteLocalExportFiles()method inclass-ghost.phpas shown in the fix above
Environment
- WordPress: Latest version
- PHP: 8.x
- Plugin: Ghost Exporter Plugin v1.6.0
Impact
The bug prevents plugin activation, making it unusable without manual code modification.
Additional Context
The fix adds the offset parameter (2) to array_slice() to properly skip the "." and ".." directory entries that scandir() returns. I've implemented this fix locally and confirmed it resolves the issue.