Forum Replies Created

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter GoSuccess

    (@gosuccess)

    Hello @avi1020p,

    Yes, I have already seen the update, thank you very much!

    It now works as expected right away. 👍

    • This reply was modified 3 months, 2 weeks ago by GoSuccess.

    @bruandet I have the same problem on all my websites. This is my analysis, which may help you reproduce and fix the error:

    Error Message

    PHP Fatal error:  Uncaught UnexpectedValueException: DirectoryIterator::__construct(/var/www/.../wp-content/session): Failed to open directory: No such file or directory in /var/www/.../wp-content/plugins/ninjafirewall/lib/class-helpers.php:29

    The Problem

    The NFWSESSION_DIR constant is defined inconsistently in two different files:

    1. In ninjafirewall.php (line 71) (incorrect):

    define('NFWSESSION_DIR', NFW_LOG_DIR .'/session');

    Since NFW_LOG_DIR = WP_CONTENT_DIR, this resolves to:

    wp-content/session ❌

    2. In lib/firewall.php (line 89) (correct):

    define('NFWSESSION_DIR', "{$nfw_['log_dir']}/session" );

    Since $nfw_['log_dir'] = wp-content/nfwlog, this resolves to:

    wp-content/nfwlog/session

    3. Additional inconsistency in lib/class-nfw-session.php (line 46):

    self::$session_dir = NFW_LOG_DIR .'/sessions';  // Note: 'sessions' with 's'

    This fallback would resolve to:

    wp-content/sessions (yet another different path!)

    How the Bug Manifests

    1. When the firewall is active: The firewall.php script runs first and correctly defines NFWSESSION_DIR as wp-content/nfwlog/session. Session files are created in the correct location.
    2. When the cron job runs: The garbage collector (nfwgccron) is triggered via WP-CLI or WordPress cron. In this context, ninjafirewall.php loads first (without the firewall), and defines NFWSESSION_DIR incorrectly as wp-content/session.
    3. The crash: The garbage collector in lib/utils.php (line 633) calls:
       $list = NinjaFirewall_helpers::nfw_glob( NFWSESSION_DIR, '^sess_', true, true );

    This attempts to iterate over wp-content/session/ which doesn’t exist, causing the DirectoryIterator to throw an UnexpectedValueException.

    Fix

    Primary Fix (ninjafirewall.php, line 71)

    Change:

    define('NFWSESSION_DIR', NFW_LOG_DIR .'/session');

    To:

    define('NFWSESSION_DIR', NFW_LOG_DIR .'/nfwlog/session');

    Secondary Fix (lib/class-nfw-session.php, line 46)

    For consistency, also change:

    self::$session_dir = NFW_LOG_DIR .'/sessions';

    To:

    self::$session_dir = NFW_LOG_DIR .'/nfwlog/session';

    Defensive Fix (lib/class-helpers.php, line 27)

    As an additional safeguard, add a directory existence check in the nfw_glob() function:

    public static function nfw_glob( $directory, $regex, $pathname = false, $sortname = true ) {
    
        $list = [];
    
        // Add this check to prevent crashes if directory doesn't exist
        if ( ! is_dir( $directory ) ) {
            return $list;
        }
    
        foreach ( new DirectoryIterator( $directory ) as $finfo ) {
            // ... rest of the function
        }
    }

    The same defensive check should be added to the nfw_glob_recursive() function in the same file.

    Steps to Reproduce

    1. Install NinjaFirewall 4.8.1
    2. Enable the firewall (this creates sessions in the correct directory)
    3. Wait for the garbage collector cron to run, or trigger it manually via WP-CLI:
       wp cron event run nfwgccron
    1. Observe the fatal error in the PHP error log
    Plugin Author GoSuccess

    (@gosuccess)

    But the slash did not appear.

    As already mentioned, we will fix the slash in a later update, because technically it makes no difference in this case.

    Plugin Author GoSuccess

    (@gosuccess)

    New update (1.2.1) is online, which should fix the “Undefined variable $numpage” error. Let me know if it works for you.

    Plugin Author GoSuccess

    (@gosuccess)

    Can you tell me which PHP and WP version you are using and are custom post types used?

    We are aware of the missing slash. Technically, it makes no difference in this case, but we will correct this in another update.

    Plugin Author GoSuccess

    (@gosuccess)

    Hi @ikiterder,

    I am pleased to inform you that we have just released a new version: 1.2.0

    The new version supports paginated …

    • categories
    • Tag pages
    • blog page
    • frontpage

    We are still working on paginated archives.

    I hope the new version will help you. 🙂

    Plugin Author GoSuccess

    (@gosuccess)

    Hi @ikiterder,

    thank you for your request! 🙂

    Paginated categories is not easy to implement. But we are working on it. The same applies to the implementation of paginated archives. However, I can’t give you an ETA at the moment.

    XML Cache already supports paginated posts and pages.

    Plugin Author GoSuccess

    (@gosuccess)

    Hi @shirtguy72,

    as of version 1.1.0, XML Cache supports paginated posts and pages.

    Plugin Author GoSuccess

    (@gosuccess)

    Hi @shirtguy72,

    sorry for the delay in replying. Did not receive a notification.

    XML Cache does not support paginated pages at the moment. We would love to offer this feature in the future. But we still have to check if and how we can implement it.

    I can’t give you an ETA on this yet, but it’s definitely something we’re looking into and will implement if possible.

    Thanks for your contribution!

Viewing 9 replies - 1 through 9 (of 9 total)