Being a plugin developer isn’t easy. You have to get your plugin to work with WordPress. But more often than not, you also need it to interact with other plugins. This interaction can take various forms. For example, you might need to modify another plugins behaviour using the plugin API. Or you might want to help customers migrate away from another plugin (or product) to yours.
This second scenario is the one that we’re going to look at in this article. It’s a good opportunity to introduce a new software design pattern. We call it the strategy pattern.
So what is this strategy pattern and what’s so great about it? Well, let’s go back to the migration scenario that we want to look at. A common way of migrating someone away from another plugin is to create an importer.
In practice, you can break the job of an importer into two smaller jobs. First, it takes data from the other plugin and converts it into data that your plugin can use. Once it’s done that, it saves that converted data into the WordPress database.
Now, let’s say that you wanted to create classes for these importers. Your first instinct might be to create a class for each importer.
Source: https://managewp.org/articles/13671/importing-data-into-wordpress-using-the-strategy-pattern
source https://williechiu40.wordpress.com/2016/10/20/importing-data-into-wordpress-using-the-strategy-pattern/
No comments:
Post a Comment