[wp-hackers] Plugin main file name

Stephen Rider wp-hackers at striderweb.com
Sat Aug 23 22:45:29 GMT 2008

On Aug 23, 2008, at 2:48 PM, Ozh wrote:

> On Sat, Aug 23, 2008 at 4:10 PM, Stephen Rider
> <wp-hackers at striderweb.com> wrote:
>> myplugin/plugin_main.php
>> anotherplugin/plugin_main.php
>> thirdplugin/plugin_main.php
> Make everything in plugin_main.php within a "if
> (!class_exists('strider_main')) class strider_main{}", and whenever
> you update this file, update all your plugins that use it

Here's what I did, but I still have a question.

I normally put all of a plugin's function in a class -- to avoid  
naming conflicts and to aid in making reusable code.

So what I did is this:  I have my "core" class -- strider_core().   
Class strider_core contains all the common code that is reused across  
pretty much all my plugins.  This file is included with each plugin.

Then, in the main plugin file, I require_once the core file, then  
create the plugin's class like so:

class myplugin extends strider_core { ... }

That way myplugin includes everything from strider_core, plus all the  
code particular to the plugin that I add to myplugin.

The strider_core class declaration is wrapped in if( !  
class_exists( 'strider_core' ) { ... }
That way if there are multiple of my plugins installed, they don't try  
to declare the class multiple times.

Okay, here's the question:

I want to give strider_core a version number.  I want the if() clause  
that checks for the class to ALSO check the version of the class (if  
it exists).  If the existing class is a lower version number (such as  
from an older version of the other plugin) I want go ahead with  
declaring the class again with the newer code.

Is there a way to redeclare a class in PHP?

Any ideas?  I'm stuck.


More information about the wp-hackers mailing list