Actions should not return anything, and action hooks are not built to do anything with a returned value. (That is what filters are for.)
If you look at the source for that particular hook, you can see that even if you return something nothing happens. Whatever you return isn’t captured. It vanishes from the code.
The sample code you found is in my opinion sloppy and confusing. I assume that the point of the return $post_id
lines is just to kill the script, which it would do, but all that is really necessary to kill the script is a simple return;
. Even a return false;
would be less confusing.
Related Posts:
- Check for update vs new post on save_post action
- How to avoid infinite loop in save_post callback
- $update is always true in save_post
- Action hook ‘save_post’ triggered when deleting posts
- get post meta before it is updated (during SAVE_POST)
- save_post action firing before I publish / save the post
- save_post action only when creating a new post
- Check if value has changed on save_post
- Minimum Word Count Before A Post Can Be Made Pending Review
- update_post_meta() not working in save_post
- How do I save each option in a multiple select menu as it’s own meta_key + meta_value pair?
- Update post on save
- Post meta checkbox becomes unchecked occasionally
- update_post_meta not working in save_post
- save_post only saves meta data on second save
- Get Post ID with insert/edit link
- How to manage saving custom field from Quick edit and Post Save using save_post action hook without colliding each other?
- Why save_post_$(custom_post_type) is fired even if I am not already saving a post?
- Set the value of custom field when post is published or updated
- pass error to admin_notices on “quick edit”/save_post action
- save_post requiere at least one uploaded file to be published
- Get $_POST & $_REQUEST values before adding/updating post
- How can I create a new user account while creating a new post, and then set that new user as the author of that new post?
- Validate post checking if child term is assigned
- Clear cache on post of one type when something happens to post of other type
- Why not fire the save_post event?
- Compare custom taxonomies of updated post (or new post) [Updated with progress]
- WordPress 4.9.8 doesn’t save if content has style=”
- Reset all transients on post or page save
- Using PODS data with save_post
- Cant’t delete my custom posts
- where does this $post_id come from?
- Update current WP post every 3 minutes [closed]
- Changing new post to “pending” on publish – but “Publish failed” – why?
- update_post_meta not working in foreach
- Save post in another table
- Strange bug on post/page save
- draft_to_pending action doesn’t seem to fire
- What action to use for when a post is saved / published, with a caveat
- Custom wp_editor doesn’t update post_content
- Save custom value to main content of post
- Check for page template on save_post hook
- Access NEW/UPDATED post values in save_post() callback function
- save button grayed out randomly
- Post editor doesn’t save embed media [closed]
- How to get a post meta value and pass that to update_option when a post is created or updated?
- WordPress save meta data : Displaying the word Array when selected
- Save current post using custom save button
- Connection Reset on post/page save
- Meta data not saved on save_post
- Insert/Update DB table when making new post or update older one
- Prevent Page/Post From Being Created based on Pages/Posts per User per Time Unit
- How to debug | Some times the “Save Draft” button seems to spin but does not actually save
- My custom title gets duplicated at every save or post update
- Use save_post to generate file on wordpress
- Detect, if post is saved manually or programmatically in save_post-hook
- Using save_post to replace the post’s title
- Force post slug to be auto generated from title on save
- Unable to prevent function using save_post firing twice
- Hook to process a new taxonomy tag before it is created?
- How to verify nonce from Bulk/Quick Edit in save_post?
- Action ‘save_post’ not working for quick edit
- How to assign default taxonomy to pages on ‘save_post’?
- wp_insert_posts Fatal error: Maximum function nesting level of ‘100’ reached, aborting!
- update_post_meta() whenever custom post type is updated
- save_post hook not triggered in WP v3.6.1
- Custom Post Custom Taxonomy Data Not Saving in Edit Screen
- post_status => publish not working
- Call add_action() in function wordpress
- Metabox saves on Update or Publish, but not on Saving Draft
- Confusion regarding Nonce & using it in Custom Columns for Saving Checkbox Value to Post Meta
- Pre insert data when adding new custom post fire a json error
- Can’t find infinite loop cause
- CPT Validation to not show “Post updated.”
- save_post custom post type ? $_POST not working?
- Run function after a post has finished saving – callback function perhaps?
- Save post meta foreach loop
- save_post hook to add terms getting deleted when using bulk edit
- When the new post which has no image published, save the specific image as the featured image ( by category )
- How to detect that the save_post hook is calling the callback associated to the current edit post page only
- How to register a widget when saving a post?
- save radio button selection in post-meta on submit
- Save / Update meta data as multidimensional array
- WordPress sent multiple requests on update
- Use value from ACF to populate other fields
- Execute php after post save/update
- Saving multiple fields (dropdown and text) in custom metabox
- Updating failed message when a wp_insert_post function is hooked to save_post hook
- WordPress dosn’t save page/post updates
- problem when uploading file by metaboxes
- How to stop post status from reverting to Published?
- Error 404 when saving or previewing one specific page [closed]
- Update post_meta post_name with the post ID from wp_insert_post after user register
- Saving metadata of related post on save_post
- Problem with executing a function on saving a post
- added a meta box to post however when saving menu while debug on throws a warning
- Using set_post_thumbnail inside save_post action gets overwritten
- if condition from post_meta not working in save_post
- Multiple triggers when publishing, saving or updating a post in WordPress
- Resaving posts to update static blocks