Best pattern to configure a site using a plugin
-
Hi,
I’m developing a plugin that adds some custom post types and makes some global configurations to the site.
I’d like to use a more “object-oriented” approach.
So I’ve developed a PluginManager that has a plugin_setup method that calls other managers that execute their setup functions. In these setup functions, there are the add_action calls. I have attached an example of this configuration.
What do you think about this approach? There are better patterns?
Any suggestions will be appreciated.
Thank you
claudio
File functions.php:
if ( ! class_exists( 'MyPlugin_Manager' ) ) { include_once 'inc/classes/class-mypluginmanager.php'; global $myplugin_manager; $myplugin_manager = new MyPlugin_Manager(); $myplugin_manager->plugin_setup(); }File class-mypluginmanager.php:
class MyPlugin_Manager { public function plugin_setup() { … // Setup of the People post type. $pm = new People_Manager(); $pm->setup(); … } }File class-peoplemanager.php:
class People_Manager { public function __construct() {} public function setup() { // Register the taxonomies used by this post type. add_action( 'init', array( $this, 'add_taxonomies' ) ); // Register the post type. add_action( 'init', array( $this, 'add_post_type' ) ); // Customize the post type layout of the admin interface. add_action( 'edit_form_after_title', array( $this, 'custom_layout' ) ); } ... }
The topic ‘Best pattern to configure a site using a plugin’ is closed to new replies.