Skip to content

fix: make a second copy of the plugin load safely - #34

Merged
Herm71 merged 2 commits into
mainfrom
fix/33-double-inclusion-guards
Nov 7, 2026
Merged

Herm71 merged 2 commits into
mainfrom
fix/33-double-inclusion-guards

Conversation

@Herm71

@Herm71 Herm71 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Closes #33

Summary

A second copy of the plugin in another directory (for example after a second zip upload) loads plugin.php under a different path, so require_once does not stop it. That copy warned on the three define() calls and then fatalled on the first unguarded function.

  • plugin.php returns early when UCSCCOMMS_PLUGIN_DIR is already defined. The first copy that loads wins, and the second copy defines and registers nothing.
  • The two ACF callbacks in plugin.php and the two shortcode callbacks in lib/functions/shortcodes.php now have function_exists() guards, in the same pattern as general.php and settings.php. Most of the diff in those files is the new indentation.
  • The settings.php and shortcodes.php include paths in plugin.php no longer start with a slash. plugin_dir_path() already ends in one, so they made a double slash.
  • New tests/DoubleInclusionTest.php includes plugin.php and shortcodes.php a second time.
  • CLAUDE.md, ROADMAP.md and the tests/bootstrap.php comment now describe the new behavior.

function_exists() guards alone do not fix this, because the constants still warn and the site would run a mix of functions from two copies. The early return is the main fix.

Test

  • composer run lint exits 0.
  • PHPUnit on PHP 8.3: 24 tests, 41 assertions, all pass.
  • Mutation check: without the early return, test_second_include_of_plugin_php_is_a_no_op fails with a registry mismatch and three "Constant already defined" warnings.

🤖 Generated with Claude Code

Herm71 and others added 2 commits November 7, 2026 09:06
A second copy of the plugin in another directory loads plugin.php under a
different path, so require_once does not stop it. That copy warned on the
three define() calls and then fatalled on the first unguarded function in
shortcodes.php or plugin.php.

plugin.php now returns early when UCSCCOMMS_PLUGIN_DIR is already
defined, so the first copy wins and the second copy loads nothing. The
four unguarded functions also get function_exists() guards, to match
general.php and settings.php. DoubleInclusionTest includes both files a
second time. CLAUDE.md, ROADMAP.md and the bootstrap comment describe the
new behavior.

Closes #33

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
plugin_dir_path() already ends in a slash, so UCSCCOMMS_PLUGIN_DIR .
'/lib/...' made a double slash in the settings.php and shortcodes.php
include paths. The general.php path already used the correct form.

Refs #33

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Herm71 Herm71 self-assigned this Nov 7, 2026
@Herm71
Herm71 merged commit d078364 into main Nov 7, 2026
3 checks passed
@Herm71
Herm71 deleted the fix/33-double-inclusion-guards branch November 7, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Review code for function_exists()

1 participant