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
- How to prevent posts from being published too close to each other?
- Passing current cookies in wp_remote_get to get Draft Post Preview
- Hook that get’s triggered when the author of a post is changed
- The hook for the AJAX Add to Cart button?
- 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
- Post publish only hook?
- Publish pending article from front end with a button?
- How to add a “publish” link to the quick actions
- Action hook ‘wp’ firing twice… why?
- How to limit user to publish post per day and per role?
- When a user creates a post (pending), send a confirmation link that allows them to publish
- How to disable drafts?
- Restrict the Number of Posts an Author can Publish (over time)?
- Add javascript when post is published
- Better post meta efficiency?
- Count singular post views automatically
- featuring old articles without messing up with the archive
- 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 to place HTML below the title of the (custom) post overview
- Limit number of posts a user can make per minute?
- 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?
- How can i do something after head like adding a hook for after head but before post
- Notification to Admin or Author upon new post [duplicate]
- How to run a function when post is edited or updated using publish post action?
- How can I create custom button in post.php
- Bulk unpublish posts between specific dates (e.g. from April 2017 and earlier)?
- How to rename “Publish” metabox title in post screen
- 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
- Automatically Updating Publish Date Bug
- 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?
- How to modify post content?
- 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
- Adding buttons to Add New Post and Add New Page
- use wpml_post_language_details function other plugin based on $post->ID [closed]
- Hide a specific category in admin All Posts page (WordPress)
- Decide user that can publish a post
- How to switch wordpress post status between publish and schedule in MySQL?
- 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
- Hooking into the post editing screen for an existing page only
- Do action on publish or update?
- transition_post_status hook doesn’t have any POST data when publish with Gutenberg [closed]
- Trying to alter the post_content through the_post
- How do I manage my users post before publish?
- Call Web Services on post first publish
- do more action after I publish a post
- How to dynamically parse and transform post/page content before displaying it?
- 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”
- why the same code got different results when using query_posts in functions.php and index.php
- Divs appearing everywhere in post content
- Display password protected posts to logged in users
- Modify posts listing at back end
- Stop wordpress from creating empty/null entries
- WordPress bulk category select when publishing post
- 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?