TIP: Plugin development using PHP classes or the “Cannot redeclare class”.
-
Hi guys, thought this might be worth of sharing:
There is a weird problem in WP – the “Cannot redeclare class” plugin activation fatall error, and as in the past, looks like this is related to WP’s hooks into /admin side for missing files at the process of initializiation of the plugin or something.
Whatever, point is – I’ve been struggling with this for couple of hours and the only solution (that is simple and powerfull enough) I’ve found – is to avoid the classes in the main plugin file!
So this stands for:
1. Use a stupid simple initiation file (the first file WP will load from you plugin directory)
2. Move all of you classes into other files (aka oldschool /includes)
3. Place a retarded check as:if(class_exists('MyMainClass'))
4. Code include of the class file and it’s initialization only if check fails (yep, class is not here yet – we go).
- The topic ‘TIP: Plugin development using PHP classes or the “Cannot redeclare class”.’ is closed to new replies.