Below I’ve included two hooks you could use. There may be better hooks depending on what you’re trying to accomplish exactly but this is what you’ve asked for. At the bottom I’ve listed some helpful resources:
Publish Post Hook
http://codex.wordpress.org/Plugin_API/Action_Reference/publish_post
function published_post( $ID, $post ) {
if( $post->post_type == 'post' ) {
...
}
if( $post->post_type == 'page' ) {
...
}
}
add_action( 'publish_post', 'published_post', 10, 2 );
Comment Post Hook
function maybe_published_comment( $ID, $approval_bool ) {
...
}
add_action( 'comment_post', maybe_published_comment, 10, 2 );
Resources
Related Posts:
- How can I edit post data before it is saved?
- Calling plugin function inside custom plugin for onclick event
- Create a post builder skin in a plugin
- Are there action hooks for comments?
- How to remove a class function from a plugin by using remove_action()?
- Advanced WordPress plugin activation detection
- Add action to custom Function
- The function called on the wp head hook becomes null
- Use action, filter, or hook to append HTML to WordPress plugin function
- add query string to all pages after user logged in
- How wordpress plugin hooks works? [duplicate]
- How to Add Extra Text In WordPress Title Before Post Publish
- Best collection of code for your 'functions.php' file [closed]
- Passing a parameter to filter and action functions
- Get a list of all registered actions
- Remote upload file to server B
- How to only hook on Single.php after content?
- Customizing subject in comment notification e-mails
- How can I log a user out of WordPress before the page loads?
- WP showing “warning: call_user_func_array()”, What to do?
- Autogenerate wordpress shortcodes using array?
- Enqueue style inside shortcode but its loaded at the bottom of page (before footer scripts)
- WooCommerce create new product and add to cart on form submit
- How can I limit functionality in one version of a plugin?
- Seeking clarification on page request life-cycle
- Shortcode display outside the div
- Good tools for locating hooks in a wordpress page/admin interface/blog post?
- How to remove action from plugin?
- do_action and hook methods
- Fatal error: Class not found in
- Is it possible to add an action to the currently running action?
- How to filter content post only on save
- Filter or action hook to insert content on admin pages before tag
- Over write plugin templates
- How to find out what blocks are added by a plugin
- How to prevent action in ajax request, when in admin side?
- template_redirect not being called when using ajax
- How to Replace Words with Hypertext Link But Ignore Previously Existed Links?
- How to add rewrite rules and pagination to retrieve attachments files?
- Can I use a method from an existing plugin as an action hook?
- Plugin custom Action Hook not working
- What are the benefit in adding hook in the init() hook?
- Debugging Technique Question re: functions.php
- add_action in functions.php, do_action in plugin?
- Override the filter from plugin in child theme
- Where to hook my plugin’s action
- How do action and filter hooks understand where to look for the core function that we hooked our function to them
- Any hook for pre-plugin-update -either bulk or single plugin update
- wordpress plugin is not activating from widget
- Edit Yoast SEO breadcrumbs output [closed]
- How to get all of the activate_plugin action parameters?
- Using a post-signup hook to get user details
- Get Time Taken By Each Action Hook in WordPress
- Best place for short bio,image and button [closed]
- What is @Action in WordPress?
- a weird attribute on every html tag
- Why do plugins often ask to add in to templates?
- remove_action not removing add_action from constructor
- How to get menu location in wp_update_nav_menu hook
- WooCommerce: after install hook
- Change Header (Logo) Based on Login
- how to change wp-admin url using function file
- same user role or copy the user role to be same as the other role
- How to hook into action/filter call
- Call javascript functions from each page
- Edit post image attributes on fly?
- Hook from plugin doesn’t fire up from external PHP script
- WordPress Custom Hook with Class method
- update_option_{$option} not working (do function after options are saved)
- Alternative Hook to the_content for Changing Background Color
- Unpublished Pages Failing To Appear On Custom Path
- add a hook of Woocommerce to a plugin but it only shows and doesn’t function properly
- Post source link plugin – small modification
- Save_post – Warning: Cannot modify header information
- Sharing varible between two add_actions
- ACF Fields are not showing up on Homepage
- Adding discount functionality to the cart
- Precheck fields when I add a new post
- Hooking into the HTML header container
- Plugin function in child theme
- WPML – Hook when language is switched (change user language)
- Passing function into add_action always returns the first argument
- {status}_{post_type} does not run correctly?
- Why is WP template_include overwritting all templates rather than specified page?
- plugin not hooking to my custom hook
- Why can’t I shove an instance of a class into a variable from a do_action hook?
- Place content inside the Post Loop
- Passing a parameter to filter and action functions
- Run only on plug-in activation instead of wp_head
- Am I using an action hook correctly?
- Conditional required fields for WordPress Contact Form 7
- Plugin Hook: Get posts
- Display_rows() and column_cb() strange behaviour
- functions.php conditional output for a single plugin
- OOP Plugin: Where should I place the action hooks in the class?
- WordPress: code structure
- Hook automatic_updates_complete to autoupdate plugin
- How to disable plugin capability : “create new category”
- Product customizing quiz – quiz adding products to the cart
- Remove and strip html tag values