wikimedia / interconnection-wordpress-theme

WordPress theme created for https://diff.wikimedia.org/
GNU General Public License v2.0
3 stars 0 forks source link

#887: Fix JetPack Email Author #42

Closed ajvillegas closed 6 months ago

ajvillegas commented 7 months ago

This change tries to fix the post author in the JetPack email notifications by updating the post_author with the first Co-Authors Plus plugin author assigned to a post. This assumes that JetPack is looking for the post_author value when creating the email notification for a post.

To Do:

Testing Instructions:

  1. Create a new post and add another user as a guest author under the "Authors" sidebar panel, then remove yourself from the list before publishing it.
  2. Once the post is published, copy the post ID from the editor URL.
  3. On a terminal window in the Altis Dashboard check the post_author with the following command: wp post get {ID} replacing {ID} with the post ID you copied above.
  4. Check that the post_author value contains the ID of the guest author and not yours.

For humanmade/wikimedia#887

ajvillegas commented 7 months ago

Thank you for the review @kadamwhite. I updated the function to use the save_post hook instead since the wp_insert_post_data doesn't run when publishing a new post.

I am still encountering some inconsistencies when testing. Mainly if I switch authors, or change the order, it doesn't seem to update the post data properly, but after some time it does. Is the data cache in the DB somehow? I've been testing with wp post get {ID} to check the post_author value.

However if I publish a post and remove myself as the author and add someone else before publishing it works consistently, and given that is the current workflow (an admin publishes someone else's post and adds them as the author), then it could satisfy the request.

I still need to test this on Dev with JetPack because I don't have a local email server setup with VIP Dev Env.

kadamwhite commented 7 months ago

Dev-env comes with mailpit for testing email unless you opt out during environment setup, although I don't know how to use it. Maybe try the CLI --help command, or look through VIP docs? It also might not be possible if the email gets sent BY Jetpack on their end

As for the hook, I'd expect save_post to fire both on insert and update, as you say 🤔 alternatively, would it be sufficient to fire when a post is moved from draft to publish with transition_post_status