Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Fatal Error: array_slice() missing argument in deleteLocalExportFiles()" #38

Open
clientamp opened this issue Nov 16, 2024 · 1 comment

Comments

@clientamp
Copy link

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:169

Current Implementation (Bug)

$filesInDir = scandir($gfiledir);
$slicesFilesInDir = array_slice($filesInDir);  // Missing required offset parameter

Fixed Implementation

$filesInDir = scandir($gfiledir);
$slicesFilesInDir = array_slice($filesInDir, 2);  // Added offset to skip . and .. directories

Steps to Reproduce

  1. Have previously used the Ghost exporter plugin (creates /wp-content/uploads/ghost-exports directory)
  2. Deactivate the plugin
  3. Install/Update to Ghost WordPress Exporter v1.6.0
  4. Attempt to activate the plugin
  5. 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:

  1. Manually delete the /wp-content/uploads/ghost-exports directory before activating
  2. Or modify the deleteLocalExportFiles() method in class-ghost.php as 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.

@PaulKempf
Copy link

Hey @clientamp,
Had a look at this issue, turns out if you already installed the plugin in the past and the folder in /wp-content/uploads/ghost-exports already exists, the plugin crashes.
I just deleted the folder, reloaded my site and the site works and the plugin is active.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants