I'm developing a plugin using the WordPress Plugin Boilerplate and am after hitting a wall.

I need to hook into when a custom post type is published (as in the user hits publish) and when its updated.

I'm fairly sure I should be looking at Post Status Transitions https://codex.wordpress.org/Post_Status_Transitions but I'm having a bit of trouble getting this to work in an object oriented way.

So I've added the action like this (rest of the class omitted):

private function define_admin_hooks() {
    $this->loader->add_action( 'transition_post_status', $plugin_admin, 'publish_my_plugin_post_type' );

and here's the the method called:

public function publish_my_plugin_post_type($new_status, $old_status, $post) {
    //do stuff here

When I try this out I get warnings that I'm missing arguments for the method publish_my_plugin_post_type. In a non OOP world these arguments are available. How can I make these variables available and still use OOP? They are variables supplied by WordPress see below:

When do_action() is called for transition_post_status, three arguments are passed to it: $new_status, $old_status and the $post object. Therefore, these are also available to be used in the callback function.


  • 2
    In your method publish_my_plugin_post_type it has three arguments.I think we need to explicitly mention 3 arguments while hooking into action add_action( 'transition_post_status', 'publish_my_plugin_post_type', 10, 3 ); – bravokeyl May 19 '16 at 9:14
  • @bravokeyl Gah! Yep that was it! Thanks for your help! – Barry Walsh May 19 '16 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.