I like to create child plugin..
Explanation :-
I have one parent plugin named X. This will work independently (like other existing plugins).
Now I decided to add some extra features to that plugin X (think of it as an upgrade). So I want to create extra features by way of another plugin Y, which will depend on (and inherit from) X.
This plugin Y will not work with out plugin X.
How can I do this?
I like to create child plugin..
Explanation :-
I have one parent plugin named X. This will work independently (like other existing plugins).
Now I decided to add some extra features to that plugin X (think of it as an upgrade). So I want to create extra features by way of another plugin Y, which will depend on (and inherit from) X.
This plugin Y will not work with out plugin X.
How can I do this?
Share Improve this question edited Sep 8, 2014 at 19:20 superjos 1075 bronze badges asked Mar 19, 2011 at 10:19 GowriGowri 8614 gold badges19 silver badges37 bronze badges3 Answers
Reset to default 20the Best way to do this is have your X plugin made with its own hooks for actions and filters so new plugins (in your case Y) could interact with plugin X's functions and data. Defining your own hooks is fairly easy and simple.
Action Hook
from the codex:
Actions are the hooks that the WordPress core launches at specific points during execution, or when specific events occur. Your plugin can specify that one or more of its PHP functions are executed at these points, using the Action API.
example of a new action hook:
Function whatever(){
//regular stuff you do normally
do_action('Name-Of-Your-Action-hook', $args1,$args2)
//regular stuff you do normally
}
Now we can interact with that function and use its arguments ($args1,$args2) using 'Name-Of-Your_hook' hook
add_action('Name-Of-Your-Action-hook','hook_function_callback');
Filter Hook
from the codex:
Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen. Your plugin can specify that one or more of its PHP functions is executed to modify specific types of text at these times, using the Filter API.
example of a new filter hook:
Function whatever(){
//regular stuff you do normally
$output = apply_filters('Name-Of-Your-Filter-hook', $output,$args1,$args2)
//regular stuff you do normally
}
Now we can interact with that function , filter $output use and its arguments ($args1,$args2) using 'Name-Of-Your-Filter-hook' hook
add_filter('Name-Of-Your_hook','hook_function_callback');
A good example to that would be contact form 7
- Contact Form 7 - Campaign Monitor Addon
- Contact Form 7 Dynamic Text Extension
- Contact Form 7 Calendar
- Contact Form 7 Textarea Wordcount
- Contact Form 7 Customfield in mail
- Contact Form 7 to Database Extension
and many more which all (most) are plugins that extend the functionality of Contact Form 7 based on its hooks.
Make some hooks in your parent plugin to which the child plugin can attach their own function. Also wrap the child plugin in if(function_exists('parent-plugin-function'))
or class_exists
if its a class.
I just went through myself and I had so many changes that I couldn't just override the actions.
I created this tool that allows you to create a child plugin like a child theme. You can make updates to the plugin and still update it without losing your changes.
I'm posting this here because it relates and hopefully becomes useful to the next person who runs into this issue.
https://github/ThomasDepole/wordpress-child-plugin-tool