You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add function_exists( 'add_action' ) check to initialization file #1270
I expect the following to run PHP Code Sniffer (phpcs)
$ composer install
$ ./vendor/bin/phpcs
Actual Behavior:
I get a fatal error because the function add_action() is undefined.
$ composer install
$ ./vendor/bin/phpcs
Fatal error: Uncaught Error: Call to undefined function add_action() in vendor/cmb2/cmb2/init.php:126
Possible Solution
If we add a function_exists() check for add_action() before calling it, we can prevent throwing this fatal error.
Possible Solution's 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.
Steps to reproduce (I have confirmed I can reproduce this issue on the develop branch):
I had the same issue with the latest version of CMB2 ,
I added the following code to the top of init.php
if (!defined('ABSPATH')) exit; // Exit if accessed directly
Also, after a simple google search, it seems this issue has crashed few websites !
I agree the preferred behavior would be to show nothing, rather than the error message. Based on all of this I'm glad to see this being added in the next release but I understand it is not an high priority to get the next release out. 😀
Activity
Add function_exists('add_action') check
MichaelHabib commentedon Jul 11, 2019
I had the same issue with the latest version of CMB2 ,
I added the following code to the top of init.php
if (!defined('ABSPATH')) exit; // Exit if accessed directly
Also, after a simple google search, it seems this issue has crashed few websites !
tw2113 commentedon Jul 11, 2019
Based on #1271 it's a change that will get included in a future release, we just haven't gotten to the point of actually releasing yet. :D
salcode commentedon Jul 11, 2019
@MichaelHabib I just wanted to chime in with some clarification about the issue I originally submitted, I assume your Google search was something like "Uncaught Error: Call to undefined function add_action() in vendor/cmb2/cmb2/init.php". The results that come back for me have pretty "deep" URLs (e.g. http://example.com/wp-content/plugins/cmb2/init.php) and with the sites I checked, if I went to the root of the website instead (e.g. http://example.com/) I didn't see the error.
I agree the preferred behavior would be to show nothing, rather than the error message. Based on all of this I'm glad to see this being added in the next release but I understand it is not an high priority to get the next release out. 😀
MichaelHabib commentedon Jul 12, 2019
Thanks for the quick updates
I'll use the work around I've applied for now, as long the fix is in the next release it's all good :D