Yes, these are probably the right calls to use for what you want.
I just checked this by adding this to my functions.php:
add_action('publish_to_draft', 'doStuff');
function doStuff() {
update_option('foo', 'bar1');
}
Then using the quick edit in the posts list to change a published post to draft, and this hook definitely ran at that point and set this option in the database.
Note that if you echo something from this hook, or expect to see something output to your browser you likely won’t see it, and you might cause an error as this might be being called via an ajax type call.
Related Posts:
- In what sequence are the hooks fired when a post is “published”?
- Does WordPress remove draft status automatically?
- What differences are there between a Privately Published post and a Draft post?
- Copy post to separate database with “add_action(….)”
- My posts are getting to Auto draft when I try to Publish
- Return All Post from publish to draft [duplicate]
- add action only on post publish – not update
- Get old values for post before saving new ones
- Is it possible to Schedule Attachments in WordPress?
- Execute function when post is published
- how to limit edit_form_after_title hook to page and post edit only?
- Elegant way to include only published posts with get_objects_in_term()?
- WordPress plugin to publish to multiple remote WordPress blogs
- Publish pending article from front end with a button?
- Action hook ‘wp’ firing twice… why?
- How to limit user to publish post per day and per role?
- How to disable drafts?
- Restrict the Number of Posts an Author can Publish (over time)?
- Add javascript when post is published
- Count singular post views automatically
- How to change post status from publish to draft using hook in wordpress?
- Publish posts only after the condition is met
- Hiding by default specific post status on backend list?
- Filter post before *editing*
- WordPress Delete hook with wp_delete_post function?
- Detect Post Type when publish_post is ran
- Custom function for “Submit for Review” hook
- First hook to use current page post id
- How can I display a specific user’s first published post?
- What Can I Use To Add A Custom Button Between Publish button and Move To Trash?
- Prevent post from being published if no category selected
- Send email to user that his post has been rejected
- How can I hook into creating a new post and execute wp_die(), before the post is inserted into the database?
- Don’t post or draft if post already exists
- Does an action fire when adding a tag via the “Tags” meta box?
- Every possible way to get data (posts) from WordPress
- publish_post conflicts with save_post
- Are posts updated or built from revisions + autosaves?
- Notification to Admin or Author upon new post [duplicate]
- How to run a function when post is edited or updated using publish post action?
- Bulk unpublish posts between specific dates (e.g. from April 2017 and earlier)?
- Action hook for new pending posts?
- How to retrieve the postID in a “image_send_to_editor” hook function?
- count the total number of comments the user has received for his published posts
- Register post status, exclude from searches
- Dashboard :10 Last draft page and 10 last pending review page (metabox)
- How can I schedule a PAGE to go live at a future date/time?
- How to give capability (publish contributors posts) to author role?
- Print a message if excerpt is empty after posts have been publish/update!
- Which WordPress hook fires after post content loaded?
- Hiding Draft Post In Admin
- What is the filter or hook to add admin controls to posts on the front end?
- Check if checkbox is marked on publish/update post
- use wpml_post_language_details function other plugin based on $post->ID [closed]
- Hide a specific category in admin All Posts page (WordPress)
- How to access $post from a callback function
- Updating post data on save (save_post vs wp_insert_post_data)
- Lost draft under all posts and drafts
- Prevent scheduled post being published if date/time is past current date/time
- Calling Different Custom Post Timestamps in a table
- transition_post_status hook doesn’t have any POST data when publish with Gutenberg [closed]
- Call Web Services on post first publish
- do more action after I publish a post
- What does WordPress do if I save a post without content/title? [duplicate]
- Adding bootstrap classes to video shortcodes
- Assign published posts to another user automatically
- preg_replace not removed “class”
- Divs appearing everywhere in post content
- Display password protected posts to logged in users
- Stop wordpress from creating empty/null entries
- Hook for changing excerpt content when excerpt not set
- How to get the old WordPress Draft Editor view back with the Word count?
- Is it possible to add a shortcode below post title?
- Automatically set post_parent value
- Function added to hook “new_to_publish” not executing – custom plugin
- How can I tell if a post has been published at least once?
- Send email for pending post
- l accidentally permanently deleted a Draft. There’s any way I can recover it?
- Add delay to publish post
- How can my plugin display a populated new post window
- Posting to WP via URL
- Is there a way to know when a page has been updated and do some action only once?
- How to set a Post’s default visibility to ‘Private’ in Gutenberg?
- WordPress doesn’t save or publish new posts
- Is update_post_meta used when save_post action hook is invoked?
- Get Category in save_post Hook
- Count singular post views automatically
- How to prevent post update using transition_post_status
- How publish post from pending status
- Bulk Post update_post_meta
- Connection dropped due to file size
- Can’t get post_updated hook to work
- wp query custom orderby not custom field
- How to remove related post from home page
- I want to send push notification just after publish a new post
- Checking if some condition is matched before inserting post into database
- Which hooks are essential for post templates?
- save_post not working
- Action while post is being published
- How can add custom commands in post-new.php in wordpress