Repository navigation
fix: make a second copy of the plugin load safely - #34
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #33
Summary
A second copy of the plugin in another directory (for example after a second zip upload) loads
plugin.phpunder a different path, sorequire_oncedoes not stop it. That copy warned on the threedefine()calls and then fatalled on the first unguarded function.plugin.phpreturns early whenUCSCCOMMS_PLUGIN_DIRis already defined. The first copy that loads wins, and the second copy defines and registers nothing.plugin.phpand the two shortcode callbacks inlib/functions/shortcodes.phpnow havefunction_exists()guards, in the same pattern asgeneral.phpandsettings.php. Most of the diff in those files is the new indentation.settings.phpandshortcodes.phpinclude paths inplugin.phpno longer start with a slash.plugin_dir_path()already ends in one, so they made a double slash.tests/DoubleInclusionTest.phpincludesplugin.phpandshortcodes.phpa second time.CLAUDE.md,ROADMAP.mdand thetests/bootstrap.phpcomment 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 lintexits 0.test_second_include_of_plugin_php_is_a_no_opfails with a registry mismatch and three "Constant already defined" warnings.🤖 Generated with Claude Code