Support

Account

Home Forums Backend Issues (wp-admin) \"On Save\" hook for individual blocks?

Unread

\"On Save\" hook for individual blocks?

  • Hey there,

    I’m wondering if this feature exists somewhere that I may be missing? Essentially, I want to be able to update fields in a block on save, or ideally, when I “click off” of the block.

    For example – I am making a Google Map block. It has an address field for a pin on the map (think for a Contact Us page). I want the map to geolocate that address into a pin via Google APIs.

    I do not want the geolocate to happen every page load. I want to be able to save the block in admin, and have that block’s “on save” hook kick in, geolocate the address, and save the latitude and longitude on hidden fields on the block. Then the front end can just use those latitude and longitude fields.

    I have this working right now via the WordPress save_post action, but it’s gross. I have to listen for the page’s save_post, then I have to regex through the page to make sure my block is in the post content somewhere, then I have to regex to see if the address is filled out and the lat/lng is NOT filled out, then I have to geolocate, then I have to regex into the black lat lng fields and inject the content, then I have to update the post.

    It is fragile and not what I’d want to do moving forward. Ideally each block would have it’s own save_post action, and I could use that in a much cleaner solution.

    Does this exist? Are there are plans for this if it doesn’t exist?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.