Add function_exists('add_action') check #1271
Merged
+5
−0
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.
Add function_exists('add_action') check to initialization file. When
loading CMB2 via Composer (and autoloading init.php), the init.php will
be loaded every time. Usually this is not a problem, however if we are
also using Composer to load a PHP development tool (e.g. PHP Codesniffer
(phpcs)), when the development tool runs it is NOT in the context of
WordPress.
Running CMB2's init.php outside of the context of WordPress
results in a fatal error because the function add_action() does not
exist. By adding this function_exists() check, we can avoid this fatal
error when autoloading init.php outside of the context of WordPress.
See #1270
Description
Check that the
add_action()
function exists before calling it ininit.php
.Motivation and Context
Fixes #1270.
Risk Level
This seems to be a relatively low risk change. Since we're checking if the function
add_action()
exists directly before calling it, the only behavior change we should get is avoiding throwing this fatal error.Testing procedure
develop tests are failing
The tests on the
develop
branch (before adding any work of my own) are currently failing.Adding my changes to master
I cherrypicked the one commit in this PR onto the
master
branch and ranphpunit
there.All tests passed when my change was introduced into the
master
branch.Types of changes
Checklist: