0

I have a function that when it comes to calling from another plugin I call it this way

add_action( 'du_postSaveEvent', [ 'Lever\Api\Providers\ShareService', 'postSaveEvent' ], 10, 3 );

This works while in a plugin path.

/public_html/wp-content/plugins/

But if I call it from a page that is in

/public_html/wp-content/themes/

the thing changes and I can not execute said action

How should the action change?

The function to call is inside a plugin and has this structure.

public static function postSaveEvent ( $new_status, $old_status, $post ) {
}

Note: That is, if I call that function from another plugin that is inside the plugins/ folder works.

But if I call it from a page that is in themes/ it doesn't work.

Edu Rafael
  • 51
  • 5

1 Answers1

0

This is most likely because in the WordPress lifecycle, plugins are loaded before the themes and can therefore execute code earlier and access more lifecylce hooks which are not available for themes.

Depending on when the hook "du_postSaveEvent" is executed, you will not be able to access it via theme, because when the theme is loaded the code already ran.

You find the lifecyle docs here: https://codex.wordpress.org/Plugin_API/Action_Reference

If you develope a plugin that runs hooks with "do_action", it is best to implement them in a hook that is run after the "after_setup_theme". (e.g. 'init')

If you don't have access to when "du_postSaveEvent" is ran, you best use a plugin to add more functions to it. Since there is no way for your theme to access it.

Michi.L
  • 36
  • 3