• Resolved gcextempora

    (@gcextempora)


    Report: require_once Error with Relative Path during WPCode Snippet Validation

    Hi,
    We have identified that WPCode snippet validation fails if a require_once statement uses a relative path and is executed during the save/activation process.1. Error Details

    The error is the classic PHP Failed opening required file.php, which is thrown when the include instruction is reached.2. Demonstration (Inconsistent Validation Context)

    Tests demonstrate that the failure is dependent on the execution of the require_once, suggesting that the Current Working Directory (CWD) during validation is not the WordPress root ($\text{ABSPATH}$):Execution of require_once ‘dir/file.php’Condition/Variable SetResult (WPCode Validation)Yes (Executed)Outside Condition, or Condition is TRUEFAILURENo (Skipped)Condition is FALSESUCCESS ✅3. Conclusion

    The WPCode validation environment does not resolve relative paths correctly. To ensure activation and reliability, we are forced to use absolute paths based on WordPress constants:

    PHP

    require_once ABSPATH . 'dir/file.php';
    
    // TEST
    // (run in snippet not applied to page)

    // Does NOT activate in WPCode -> error
    require_once 'dir/file.php';

    // Does NOT activate in WPCode -> error
    if(empty($associato)){
    require_once 'dir/file.php';
    }

    // ACTIVATES in WPCode -> no error
    if(!empty($associato)){
    require_once 'dir/file.php';
    }

    // ACTIVATES in WPCode -> no error
    $associato = '123';
    if(empty($associato)){
    require_once 'dir/file.php';
    }

    // Does NOT activate in WPCode -> error
    $associato = '123';
    if(!empty($associato)){
    require_once 'dir/file.php';
    }

    Behavior can lead to ambiguous results.

    Thank you for your attention.

Viewing 1 replies (of 1 total)
  • Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @gcextempora,

    Thank you for bringing this to our attention. This is expected behavior since WPCode enables dynamic code execution, and in general, using absolute paths is recommended.

    WPCode executes the code in the context of the plugin files so it’s not going to execute the code in the WP root.

    Let me know if I can provide more info.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.