Whenever a new post is created, we can use the automation features to validate and modify the content of the post.
The query in this tutorial lesson checks if a certain mandatory block is present in the post and, whenever missing, it adds it.
This GraphQL query checks if the mandatory block wp:comments
has already been added to the post. If missing, it is added at the bottom of the content.
Save this content as a Persisted Query, with slug insert-mandatory-comments-block-if-missing
:
This PHP code hooks into WordPress action draft_post
to execute the Persisted Query (via the Internal GraphQL Server extension):