jaredatch/Custom-Metaboxes-and-Fields-for-WordPress — Issue #57: Check version when multiple themes/plugins use it
Author: billerickson
Created: 2011-12-15 18:31:08+00:00
State: open
Labels: feature request

I'll often have the metabox code running in the theme's Core Functionality plugin and a few other plugins (ex: Genesis Title Toggle). Right now we have a pretty basic check: if the class has already been declared, don't do it again.

Now that there's more themes/plugins using it, there's a better chance that some will be using newer versions than others in a single install. I might keep my public plugins up-to-date (Genesis Title Toggle), but the Core Functionality plugin is frozen in time since no one is updating it.

If the older version happened to be loaded before the later version, then the plugin that depends on the features of the later version could fail. I haven't run into this issue yet, but its best to address this now than when there are known incompatibilities.

It would be nice if we could add some type of version checker into the logic. When we include init.php, have it check to see if there's a current version loaded, and if so, if the current version is a newer version. If the cmb_Meta_Box class that's loaded is an older version than the one you're including, remove it and use the new one.

Include a public variable in the cmb_Meta_Box class called $version, then somehow use version_compare() to compare the two.

- If no cmb_Meta_Box class is exists, load this one
- If cmb_Meta_Box class does exist, compare $version in each.
- If this one is newer than the currently loaded one, remove the current one and use this one

It would also be nice to offload all this logic into the init.php file. Instead of adding all the class_exists stuff to your functions.php, just require_once( init.php ) and it will do the logic for you. This would also prevent people from including init.php twice (this issue has come up a few times), and should be backward compatible with versions that check if the class exists in their functions.php file (it just checks twice).