Skip to content

Conversation

@imantsk
Copy link
Member

@imantsk imantsk commented Dec 16, 2025

Fixes #311 #317

Summary

  • Fixes Multisite “Menu Settings → Snippets” not restricting subsite access by enforcing the network capability when the subsite Snippets menu is disabled (src/php/class-plugin.php).
  • Fixes trashed network snippets executing on Multisite by ensuring active = -1 (trashed) never qualifies as executable when building the active-snippet list (src/php/class-db.php, src/php/flat-files/classes/class-snippet-files.php).
  • Fixes file-based execution “Cannot redeclare …” collisions in Network Admin by ensuring the “local site” flat-file index uses the site table (not the network table) so the same network snippet isn’t loaded twice (src/php/flat-files/classes/class-snippet-files.php).

Testing

#317 (trashed network snippets executing / file-based collision)

  1. On Multisite, create a Network snippet using the issue’s “green banner” code and Save and Activate → banner appears.
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>';
}
  1. Deactivate → banner disappears.
  2. Trash the snippet (inactive) → banner stays gone; confirm it does not execute while in Trash.
  3. Restore → snippet returns as inactive; banner still gone until re-activated.
  4. Repeat steps 1–3 but trash while active → banner stops immediately.
  5. Enable file-based execution, repeat steps 1–5, and confirm no fatal Cannot redeclare ... occurs.

#311 (Menu Settings restriction)

  1. Network Admin → Settings → Network Settings → Menu Settings: uncheck Snippets, save.
  2. Log in as a regular subsite admin → Snippets menu is hidden.
  3. Direct URL check as subsite admin: wp-admin/admin.php?page=snippets / wp-admin/admin.php?page=add-snippet should be blocked.
  4. Re-check Snippets in Menu Settings → subsite admin can see/access Snippets again.

@imantsk imantsk requested a review from louiswol94 December 16, 2025 11:04
@imantsk imantsk self-assigned this Dec 16, 2025
@imantsk imantsk added the run-tests Trigger automated tests label Dec 16, 2025
@imantsk imantsk added multisite Apply this tag in conjunction with "run-tests" to use a multisite testing environment build Adding this label will trigger the zip build action labels Dec 18, 2025
@imantsk imantsk added build Adding this label will trigger the zip build action run-tests Trigger automated tests and removed build Adding this label will trigger the zip build action run-tests Trigger automated tests labels Dec 18, 2025
@imantsk imantsk added build Adding this label will trigger the zip build action and removed build Adding this label will trigger the zip build action labels Dec 18, 2025
@imantsk imantsk added the build Adding this label will trigger the zip build action label Dec 18, 2025
@code-snippets-bot
Copy link
Contributor

code-snippets-bot commented Dec 18, 2025

Download and install

📦 code-snippets.3.9.3.zip

@imantsk imantsk added run-tests Trigger automated tests and removed run-tests Trigger automated tests labels Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Adding this label will trigger the zip build action multisite Apply this tag in conjunction with "run-tests" to use a multisite testing environment run-tests Trigger automated tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Network Settings Option to restrict Snippets Menu doesn't work

4 participants