The function is wp_insert_post()
, and as you can see there are some hooks you can use to modify data. wp_insert_post_data
is a filter that gets all data right before it will be inserted into the database, so you modify it there and don’t need to do anything to get it saved. At the end of the function you can see the save_post
action and its equivalent wp_insert_post
, which are more appropriate if you want to do something (instead of change something).
These functions are fired when a post is saved, not only when it is published. For the publish action, look at wp_transition_post_status()
, which has three hooks:
transition_post_status
, called with the new and old statuses, and the post data{$old_status}_to_{$new_status}
, likedraft_to_publish
, called with the post data{$new_status}_{$post->post_type}
, likepublish_page
, called with the post ID and post data
Related Posts:
- Best collection of code for your 'functions.php' file [closed]
- Should all plugins be encapsulated in a Class?
- How can I edit post data before it is saved?
- How can I delete orphan keys in WordPress database tables?
- Is it a good idea to edit an already existing plugin to add more functionality?
- OpenID for WordPress 3.x? [duplicate]
- Get a button for in the Editor
- Plugin (or Theme) containing its own Plugins?
- How do I extend one plugin I’m writing with another I’m writing using classes?
- How to create extendable wordpress plugins
- Some way to Flush or Overwrite all Imported Content in a Site for a Fresh Import – How?
- Which functions in theme or plugin load first
- Add CSS animation as Preloader to WordPress
- Image Crop/Resize Function/Code Sinppet/Plugin to adjust/crop images during upload
- WP get_permalink Return Wrong URL
- WP Plugin for Terms of Use
- How to add product images using script?
- Woocommerce: Changing the variations select default value? [closed]
- Automagic Link Shortening for Non-Hosted WP
- Setting up widgets in wordpress with a unique ID for the after_title argument
- Akismet plugin is deleting spam despite preferences
- MailChimp integration that allows users to select from multiple lists [closed]
- Distributing and packaging plugins
- Use plugin or custom post type for game score functionality
- Multiple Instances sharing the same database in a development environment
- How to Replace Words with Hypertext Link But Ignore Previously Existed Links?
- How to add rewrite rules and pagination to retrieve attachments files?
- Copyright messages for a particular set of pages
- How to check what plugins used to be on a WordPress installation?
- Possible to replicate economist.com’s debate section in wordpress? [closed]
- FacetWP group listings by custom field [closed]
- Get IDs of Images from Gallery Block in InnerBlocks of a Custom Gutenberg Block
- How to embed HTML code from WP Coder plugin (or other) into Main Index Template of the theme
- WordPress plugin – Error “Plugin generate 2890 characters of unexpected output when activated”
- Remove Duplicator plugin from admin menu if not an administrator
- Input with spaces in Shortcode attributes overwritten by defaults
- Add a custom form on the post-new.php admin page
- Edit Yoast SEO breadcrumbs output [closed]
- Do widget options need to be escaped widget()?
- Is there any W3C compatible Share & Follow plugin?
- In the archive widget, how do I sort in between two years?
- Fromcraft Plugin On click submit button [closed]
- creating a custom shop page display on archive woocommerce
- polylang + category/tag custom language link
- How to redirect users to their profile after they successfully edit their profile
- Getting Theme element into plugins page editor in wp admin
- GeoMashup plugin: how to customize cluster markers / icons? [closed]
- Creating Featured Content Boxes
- Basic gallery plugin suggestion [closed]
- Free paypal cart solution [closed]
- Which plugin can do horizontal scrolling of RSS feeds in WordPress [closed]
- I am trying to make a field show and save from quickedit screen
- Moving FB comments at the end of page
- Customizing a blog page layout
- Hide a certain category name from Related Posts
- how to add custom info on author page? plugin, child theme?
- display unique post per category
- Widget where it can make changes to the container
- Call javascript functions from each page
- Can’t create new CPTs when menu hidden
- Gathering all Custom Post Type posts in to array/object the proper way
- Link Posts to External URL
- Multiple Post Thumbnails Plugin – Need help with code
- Custom Post Type, Custom Columns List
- How to prevent plugin, theme installation failures on WordPress?
- Check if theme supports sidebar
- WordPress search input in database, to edit information via form and update the database
- Adding category base to url in custom post giving 404?
- Post source link plugin – small modification
- Can we hide a certain user in WP?
- How Can I Increase Breadcrumb Position Count (Starting From 2)?
- WordPress hierarchy clarification, does post_type_archive take precedence over taxonomy-term archive?
- Create survey that redirects to sidebar menu customized to answers
- Load my Inline js footer area
- Move plugin upload folder from mywebsite.com/wp-content/uploads/pdfuploads to mywebsite.com/pdfs?
- Woocommerce list variations that are added already to cart in Single Product
- Flexslider empty slide
- How to fix slow comment query?
- Share on social media created listing after submission
- Translation plugin with default language?
- Best approach to serve static content within a regular page
- Custom pages with plugin
- WP plugin calls for custom pages
- Changing the body of mail sent to new user registration
- Which One Is Better For Managing Add Ons For Extensible Plugin?
- Multiselect value in wp_query
- get_var result empty for query of custom table in plugin admin
- Posts are deleted everyday at night
- [Custom field template plugin] Upload limited to 20 inputs file
- I want to remove the register/login WordPress top bar from my website
- Change the behaviour of archive cpt category and single cpt by plugin, not by theme
- do_shortcodes() isn’t working
- WordPress Code Access to Restricted Content without Registration
- What can I do to customize a widget provided with this plugin? from where have I to start?
- WordPress: code structure
- Can anyone tell some online tuts for plugin development for beginner? [closed]
- How to pre-set WordPress settings for specific posts?
- How to Add Extra Text In WordPress Title Before Post Publish
- Take Elementor For Email FIeld Check if user is registered. IF not registered then register on woocommerece
- How to create specific wordpress Table