Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I like to create child plugin..

Explanation :-

I have one parent plugin named X . This will work independent( like other existing plugins). now i decided to add some extra futures to that plugin X(like upgrade).so i want to create extra futures with another plugin this will depend on X . this will not work with out X .

How cam i do this ?

share|improve this question
add comment

2 Answers 2

up vote 10 down vote accepted

the 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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.