[wp-hackers] Sharing codebase between plugins
Guus (IFS)
guus at inspiration-for-success.com
Thu Jun 5 13:52:45 UTC 2014
I am using a library file with some useful stuff in multiple plugins and
just set a constant to check if the code is already included.
<?php // start of library file
if (!defined('_MY_LIBRARY_FILE_INCLUDED')) {
#define('_MY_LIBRARY_FILE_INCLUDED',true);
libraryFunction1() {
// code
}
libraryFunction2() {
// code
}
}
// end of library file
?>
-----Original Message-----
From: Nikola Nikolov
Sent: Thursday, June 05, 2014 5:27 AM
To: wp-hackers at lists.automattic.com
Subject: [wp-hackers] Sharing codebase between plugins
What do you do when you want to avoid code duplication by sharing the same
code base between multiple plugins?
Here's the situation that I'm in:
I have a plugin that adds some custom post types and functionality. Another
plugin that uses similar functionality is going to be developed. Possibly
in the future more plugins that use those post types will also be created.
So the idea is to separate out a "core" plugin that will allow any of the
plugins to function both on their own and combined, without having to ship
the code with each one(well - probably we'll need at least an archive of
the core plugin).
Now my question is how to handle that dependency(note that my client would
prefer if the core plugin is not listed on the plugins page - not sure if
that's really possible).
Right now I've thought about the following solutions:
- Have each of the plugins contain a .zip archive with the core plugin.
Then perhaps use https://github.com/thomasgriffin/TGM-Plugin-Activation in
order to define the dependency in each plugin. I'm just not sure how it
would handle updates - so when the user updates a sub-plugin it should
update the core plugin if the sub-plugin is bundled with an updated version
- Copy the core plugin as a mu-plugin if it's not already there. Again not
sure how to handle updates. Also when should I copy the plugin files - what
if FTP credentials are required?
I think my main concern are updates.
For instance how to make sure that I'm using the correct core base? What if
the user updates one of the sub-plugins and that updates the core plugin,
but they don't update the rest of the sub-plugins? Ideally I should have
things compatible between versions, but what if I have to introduce a
change that is not compatible?
I also looked at the Plugin Dependencies plugin (
https://wordpress.org/plugins/plugin-dependencies/ ), but I don't really
want to add another plugin to the bundle.
Thanks,
Nikola
_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers
More information about the wp-hackers
mailing list