I am trying to create a hook in one Wordpress plugin that can be used by other plugins. First, is this possible? I am also posting some additional arguments, so this may be 2 questions in one, as I am having trouble finding the final information on how to do this.
Here is what I have tried so far:
In the plugin that creates the hook (call it plugin 1), I added:
do_action('plugin1_hook', $customArg1, $customArg2, $customArg3);
at the point where I want the crane to fire. Then, in another plugin (plugin 2), I added:
add_action('plugin1_hook', 'my_function');
and
function my_function($customArg1, $customArg2, $customArg3) {
However, this does not seem to work. My confirmation for this was Word_post for Wordpress, which is defined by Wordpress as:
do_action('comment_post', $comment_ID, $commentdata['comment_approved']);
and I use like:
add_action('comment_post', 'my_comment'); function my_comment($comment_id) {
The above snippet is working correctly.
php wordpress hook
Ryan elkins
source share