Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_message_action passes post ID of the workflow post rather than an ID of the triggering post #109

Open
jazzsequence opened this issue May 6, 2020 · 3 comments

Comments

@jazzsequence
Copy link
Contributor

The documentation and sample code for Event::add_message_action() indicates that a $post_id parameter is passed into the callable parameter. However, the post ID that's actually passed is the ID of the hm_workflow post, not of the post itself. Therefore, the sample code provided:

Event::register( 'action_that_passes_post_object' )
  ->add_message_action( 
    'view', 
    'View post', 
    function ( $post_id ) { 
      return get_the_permalink( $post_id ); 
    }
  );

Would actually return the permalink of the workflow post, rather than the actual post to be viewed. Adding a callable $args parameter and $schema does not appear to make any difference.

@jazzsequence
Copy link
Contributor Author

Example code:

		->add_message_action(
			'preview',
			'Preview translated post',
			function ( $post_id ) {
				var_dump( $post_id ); // This prints the post ID of the hm_workflow  post.
				var_dump( get_post_type( $post_id ) ); // This prints hm_workflow.
				var_dump( get_post_meta( $post_id ) ); // This prints meta data for the hm_workflow post.
				return get_post_preview_link( $post_id ); // This would be the preview link of the Workflow post, not the post being worked with.
			},

Example data:

string(5) "69465"
string(11) "hm_workflow"
array(7) {
  ["_edit_lock"]=>
  array(1) {
    [0]=>
    string(23) "1588796820:120012219942"
  }
  ["_edit_last"]=>
  array(1) {
    [0]=>
    string(12) "120012219942"
  }
  ["event"]=>
  array(1) {
    [0]=>
    string(80) "a:2:{s:2:"id";s:40:"notify_content_manager_on_post_available";s:4:"data";a:0:{}}"
  }
  ["subject"]=>
  array(1) {
    [0]=>
    string(40) "Subject"
  }
  ["message"]=>
  array(1) {
    [0]=>
    string(115) "Message"

https://github.com/humanmade/playstation/blob/testing-workflows-destinations/content/mu-plugins/psn-l10n/inc/notify.php#L42-L50

@roborourke
Copy link
Contributor

The post ID you're receiving could possibly what's in the global scope at that time. It's strange though.

The arguments are just what are passed via do_action( 'name', $arg1, $arg2 ... ) - in your case it's the args passed by l10n_action_copy_post_to_site, it seems strange that it would be passing the workflow post ID there. I can't find any reference to that action in the codebase so I'm not sure how to debug it any further.

@jazzsequence
Copy link
Contributor Author

the action hook being used as a trigger is here: https://github.com/humanmade/playstation/blob/71f6b4cfdc1b9e2fed36694ff277fd28571a0070/content/mu-plugins/psn-l10n/inc/posts.php#L226
basically, we switch to the blog we're sending the post to, and then schedule an event to fire that actually copies the post, which triggers the action in the process

I can confirm after testing default workflow events, this may be related to the fact that the site where the workflow is saved is different than the site triggering the workflow but I can't find anything in the code that would explain why that would be the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants