Skip to content

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

@clientamp

Description

@clientamp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions