Using metabox in few plugins at the same time
- This topic has 5 replies, 2 voices, and was last updated 8 years, 6 months ago by
Anh Tran.
-
AuthorPosts
-
September 26, 2016 at 10:15 PM #4150
oleg.iondigi
ParticipantHi, I have problem with redeclaring class. I use metabox built-in theme plugin and after installing WPML pluging fatal error occurs. All files included using "include_once" inside "class_exist()" condition but error still occurs.
if( !class_exists('RWMB_Autoloader') ) include_once( 'inc/meta-box/meta-box.php' );
Fatal error: require(): Cannot redeclare class rwmb_autoloader in /usr/home/example.com/web/wp-content/plugins/brooks_core/inc/meta-box/inc/autoloader.php on line 179
September 27, 2016 at 10:26 PM #4155Anh Tran
KeymasterI think it’s best to check by
if ( ! defined( ‘RWMMB_VER’ ) )
. Checking by autoloader class seems too late.However, I would recommend using TGMA class. It allows you to use the latest version of the plugin among themes/plugins.
October 6, 2016 at 8:34 PM #4246oleg.iondigi
ParticipantThis didn't the trick.
Same problem with Timeline Express plugin.
Fatal error: Cannot declare class RWMB_Field, because the name is already in use in /wordpress/wp-content/plugins/brooks_core/inc/meta-box/inc/field.php on line 7
I can't get it across how to check if your plugin is not used by another plugin initialed later.
P.S I'm using TGMA class for required theme plugin, but users are going to add plugin they wish.October 8, 2016 at 1:45 PM #4257Anh Tran
KeymasterHmm, I've just tried including the plugin into 2 test plugins and it doesn't generate any error: http://prntscr.com/cr8ix3
Here is the test1/2 plugin main file:
<?php /** * Plugin Name: Test 1 * Plugin URI: * Description: * Version: 1.0 */ require_once 'meta-box/meta-box.php';
Meta Box plugin is put in
meta-box
folder inside the plugin http://prntscr.com/cr8j6v.The test for
RWMB_VER
constant is not needed as the plugin already check that.October 13, 2016 at 6:16 PM #4296oleg.iondigi
ParticipantHi, thanks for your investigation.
I dived into the Timeline Express and find out the lines doing the error. Actually, the function new_cmb2_box([...]) calls an error.function new_cmb2_box( array $meta_box_config ) { return cmb2_get_metabox( $meta_box_config ); } function cmb2_get_metabox( $meta_box, $object_id = 0, $object_type = '' ) { if ( $meta_box instanceof CMB2 ) { return $meta_box; } if ( is_string( $meta_box ) ) { $cmb = CMB2_Boxes::get( $meta_box ); } else { // See if we already have an instance of this metabox $cmb = CMB2_Boxes::get( $meta_box['id'] ); // If not, we'll initate a new metabox $cmb = $cmb ? $cmb : new CMB2( $meta_box, $object_id ); } if ( $cmb && $object_id ) { $cmb->object_id( $object_id ); } if ( $cmb && $object_type ) { $cmb->object_type( $object_type ); } return $cmb; }
There are used https://wordpress.org/plugins/cmb2/ plugin, that seems it is not compatible with your plugin. Any idea to fix that.
October 18, 2016 at 4:46 PM #4314Anh Tran
KeymasterThat code above belongs to cmb2 plugin, which is a totally a different thing. Meta Box and cmb2 works similar but they don't share any common API. I couldn't understand why it can generate the fatal error above.
-
AuthorPosts
- You must be logged in to reply to this topic.