-
Notifications
You must be signed in to change notification settings - Fork 572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple CMB2s and helper-functions.php fatal errors #520
Comments
So you can get around this by slighly modifying the bootstrap include like so:
The issue with this is not every plugin and theme author will include CMB2 like this... so, we run into the conflict with these helper functions. I still propose that these are wrapped in |
Hey Devin, Are your plugins requiring the CMB2 |
Hey @JPry they are using |
There are so many checks in place by the time that require is called, that there should never be a conflict. Including init.php is the correct way to do it. |
@jtsternberg there are indeed a couple checks in place, but as we see there are still conflicts reported. I suggest just keeping an eye out in the future for this in case it's reported more frequently. Closing for now. |
@DevinWalker first time I've seen this being reported for CMB2, as it's been explicitly built to handle those scenarios. Would love more details for how I can reproduce the issue. We use CMB2 all day every day at WDS, with it being bundled in a variety of our plugins, etc, and have yet to run into this. |
@jtsternberg the best way to reproduce it is to download and install Give https://wordpress.org/plugins/give and Maps Builder https://wordpress.org/plugins/google-maps-builder/ from the repo. Give includes CMB like:
Note: I have added an additional check for Maps Builder was a bit different. I had just included it like so:
... but now I've changed it to be like the new Give implementation if you look at the master branch. It appears to have resolved the issue but if you want to reproduce it install both repo version since this hasn't been pushed yet. The main issue comes from people simply copying the include method from Getting Started: https://github.com/WebDevStudios/CMB2/wiki/Basic-Usage which doesn't actually check if CMB2 has been loaded already. Let me know if you have any questions ;) |
@jtsternberg same issue for me. I have a custom theme that includes CMB2 with the init file. if ( file_exists( __DIR__ . '/inc/cmb2/init.php' ) ) {
require_once __DIR__ . '/inc/cmb2/init.php';
} The CMB2 plugin was also installed to ease the updates of the library before an update of the theme is available. After the update of the CMB2 plugin to the latest version, I have the following error:
When I change the test in the theme to load CMB2 as suggested by @DevinWalker, there's no more fatal error. if ( file_exists( __DIR__ . '/inc/cmb2/init.php' ) && !defined( 'CMB2_LOADED') ) {
require_once __DIR__ . '/inc/cmb2/init.php';
} |
Looking into this. |
…at (to keep old versions from loading as well). Fixes #520
…at (to keep old versions from loading as well). Fixes #520
This should be fixed with 2.2.1, please update wherever possible. |
@DevinWalker It definitely was only an issue with 2.2.0, and I wish I would have caught it before the release, but thank you for calling it out earlier. |
No problem, glad it's addressed |
CMB2 - v2.2.6, v2.4.2 - multiple plugin with cmb2 not working |
What errors are you seeing? |
If I have two plugins installed that both use CMB2 for their options/fields I see:
Fatal error: Cannot redeclare cmb2_dir() (previously declared in /srv/www/wordpress-default/wp-content/plugins/.../includes/libraries/cmb2/includes/helper-functions.php:18) in /srv/www/wordpress-default/wp-content/plugins/.../includes/libraries/metabox/includes/helper-functions.php on line 18
I see that it's simply required here: https://github.com/WebDevStudios/CMB2/blob/master/init.php#L144
Shouldn't these functions be wrapped in a
function_exists()
conditional? How can multiple plugins/themes use CMB2 successfully with the helper functions included like this?The text was updated successfully, but these errors were encountered: