Skip to content

Fix trashing a snippet in Network Admin activating it on Multisite #317

@code-snippets-bot

Description

@code-snippets-bot

Current behavior

Trashing a network snippet in Multisite activates it regardless of its previous state. The Trash functions as a hidden 'enabled snippets' list, which is counterintuitive and potentially dangerous.

Steps to reproduce

  1. Open this WordPress Playground with Multisite: WordPress Playground
  2. Add the following test code:
    add_action('wp_footer', 'snippet_active_banner');
    add_action('admin_footer', 'snippet_active_banner');
    function snippet_active_banner() {
        echo '<div style="position:fixed;bottom:0;left:0;right:0;background:#4caf50;color:#fff;text-align:center;padding:10px;font-weight:600;z-index:999999;">✓ This Code Snippet is active!</div>';
    }
  3. Click Save and Activate, navigate back to All Snippets → green banner appears
  4. Deactivate the snippet → green banner disappears
  5. Trash the deactivated snippet

Bug

  • Green banner reappears → trashing has activated the snippet
  • Trashing an inactive snippet → becomes active until deleted from Trash
  • Trashing an active snippet → remains active until deleted from Trash

Observations

  • Expected: Trashing should deactivate a snippet. Trashed snippets should never execute.
  • Actual: Trashing activates the snippet. All trashed snippets execute their code.

Additional context

  • This exact snippet breaks the site with: Fatal error: Cannot redeclare snippet_active_banner() when tested on multisite and with file-based execution enabled.
  • The trash to activate behavioral glitch is not present with file-based execution enabled.
  • Expected:
    • Snippet to work normally with and without file-based execution
    • Trashing a snippet must not reactivate it in any scenario
  • Confirmed, but present only on multisite

Reference

Support forum link

Metadata

Metadata

Labels

supportGeneral question or request for help

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions