Skip to content

How to differentiate between REST and POST requests of Gutenberg inside "save_post"? #12903

@manzoorwanijk

Description

@manzoorwanijk

As we know that Gutenberg sends two requests when we hit the Publish/Update button:

  1. Request to WP REST API to create/update the post
  2. Request to post.php to save/submit the metaboxes

save_post is triggered by both the requests. How do I know inside the save_post callback that the post is created/updated via Gutenberg, preferably in the second request? This is to avoid the double effect of the hook.

I know some would suggest to add some meta value in the first request and use it to short-circuit the second callback or use a transient in a similar way. Filling up the meta table with useless data is not a good idea and transients don't look to be a better solution IMHO.

Is there a consistent query argument or a header that can be relied upon? I couldn't find any such thing in the two requests.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions