Support Forum
Hi, 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
I 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.
This 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.
Hmm, 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.
Hi, 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.
That 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.