• Hi WPCode team,
    First of all, thank you for this great plugin. I’ve been using it to manage my code snippets and it’s been very helpful.

    I wanted to report an issue I encountered when pasting a snippet that starts with <?php declare( strict_types=1 );. When I saved and activated the snippet, it generated a fatal error: strict_types declaration must be the very first statement in the script.

    The problem is that WPCode (or any snippet manager plugin) already handles the PHP opening tag and execution context, so including <?php declare( strict_types=1 ); in the snippet creates a conflict.

    Here’s what happened:

    1. A plugin support agent suggested to add this snippet to disable their Site Health integration:
    <?php declare( strict_types=1 );

    add_filter( 'shield/can_run_site_health_security', '__return_false' );
    1. I pasted it into WPCode and saved/activated it
    2. This caused a fatal error that broke my site
    3. Even worse, while this issue was presen WPCode was reporting other snippets as broken when they were actually working fine (probably because the error corrupted the snippet validation state).
    4. Once i removed the real corrupted snippet I was able to reactivate other snippet marked as broken for error by your plugin workflow.

    Suggestion:
    It would be great if WPCode could automatically detect when a pasted snippet starts with <?php declare( strict_types=1 ); and either:

    • Strip it automatically before saving
    • Show a warning to the user explaining that this declaration is not needed in snippet managers
    • Handle it gracefully to prevent fatal errors

    This is important because many plugin developers provide complete code snippets (with the PHP opening tag and declarations) in their documentation, and users like me often copy-paste them directly without realizing they need to be modified for snippet managers.

    Thanks for considering this improvement!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support markomiljanovic

    (@markomiljanovic)

    Hi @peopleinside,

    Thank you for reaching out.

    You’re right that there’s an issue here, though the cause is slightly different from the PHP opening tag itself. WPCode actually strips the leading <?php automatically when you save a snippet, so that part isn’t the problem. The real culprit is the declare(strict_types=1) statement. PHP requires that declaration to be the very first statement in the entire script, and because WPCode runs your snippet inside its own execution context (alongside your other active snippets), that condition can never be met.

    For performance, WPCode runs your active PHP snippets together in a single execution pass, and this particular type of fatal error stops that whole pass before any of them get a chance to run.

    The good news is the fix on your end is simple: you never need the <?php tag or the declare(strict_types=1) line in a snippet manager. Just paste the actual code, like this:

    add_filter( 'shield/can_run_site_health_security', '__return_false' );

    WPCode handles the PHP context and execution for you, so the snippet will work exactly as intended without those leading lines.

    I’ve also passed your suggestion along to our development team, automatically detecting and stripping a leftover declare statement (or warning about it) is a great idea. Thank you for taking the time to suggest it.

    Let me know if I can provide more info.

    Thanks,

    Thread Starter peopleinside

    (@peopleinside)

    Thank you 😊 It’s all, you can mark this resolved as you think this is resolved.
    This was just a feedback report for you.

    • This reply was modified 2 days, 2 hours ago by peopleinside.
Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.