You won’t get a comment ID until the post is is inserted into the database. Before that point, the ID doesn’t exist. You have to use a hook that fires after that event…
1735 /**
1736 * Fires immediately after a comment is inserted into the database.
1737 *
1738 * @since 1.2.0
1739 *
1740 * @param int $comment_ID The comment ID.
1741 * @param int|string $comment_approved 1 if the comment is approved, 0 if not, 'spam' if spam.
1742 */
1743 do_action( 'comment_post', $comment_ID, $commentdata['comment_approved'] );
Related Posts:
- Writing a plugin that notify my friends of new post that mentions(@) them
- Why are two functions over-riding each other?
- Comment `Reply` link doesn’t work if comments are loaded from ajax
- comment_email hook doesn’t seem to work for comment editor field
- Show comments fields in two columns
- How do I alter the comment form ‘allowed tags’ text in a plugin?
- Can wp_list_comments output into variable?
- Comments do not respect display_name setting, how to make plugin to overcome this
- $reverse_top_level works the opposite way according to Codex?
- How to integrate CLEditor to comment system?
- Get attachments from a post
- is pre_get_comments not working?
- How to replace default comments with custom HTML?
- Custom avatars in wordpress comments?
- how to load the comment template from a plugin
- How to get the number of pages when paginating comments?
- How does “Your comment is awaiting moderation” work?
- how to get the top 10 popular blogs
- disable defaault wordpress comments from a plugin
- How to show comments from different Plugins to same post type?
- How to check if `comment_meta` exists before inserting the comment?
- How to get the `comment_post_ID`?
- Email content as comment
- Stop theme displaying comments
- Get Commentor IP When Marking Comment As Spam
- isset($_POST[‘submit’]) ignored on comment submission
- How do I add CSS options to my plugin without using inline styles?
- How to override existing plugin action with new action
- Add custom TinyMCE 4 Button, Usable since WordPress 3.9-beta1
- How to store username and password to API in wordpress option DB?
- How do I create links at the top of WP_List_table?
- Is it worth checking if class_exists when developing a plugin and how to do it?
- Why Does get_posts() Return an Empty Set?
- Get list of available wordpress actions
- Where to enqueue stylesheets for plugin?
- How can the tinyMCE dom be manipulated (offical API does not seem to work)?
- stray elements
- Deletion of shared options using uninstall.php
- Pass javascript result to shortcode executer function
- Plugin Settings not Saving on Ajax re-ordered table
- Undefined function wp_set_password
- WordPress password reset – why post rp_key?
- How to modify the new WordPress 4.5 link inline toolbar
- Proper way to hook wp_get_attachment_url
- How to install WordPress Popular Posts plugin twice?
- Get the link text
- Multisite plugin development and wp_enqueue_script
- Prevent plugin from deleting important directories
- Default category got deleted. How to get it back as ID=1?
- Is Dreamweaver CS5 a serious choice for theme/plugin development?
- What allows a template file from plugin to be copied in child theme and overridden?
- Create a custom display order in the main menu
- Override the default Add/Edit site forms of the Network Panel in custom plugin
- add more custom post types and custom role to the code
- Executing a function upon webhook calling wordpress
- How to display additional info in the plugins admin table?
- A better way to include localized labels in WordPress plugins
- How a deprecated function can crash WordPress site while upgrading
- plugin settings – uploading multiple files with a single button
- Getting term_id for newly created or edited term
- How to insert text at the current cursor position in Gutenberg?
- How to fix this URL error in WordPress ” data-wplink-url-error=”true”>
- Remove unwanted elements for a wp_nav_menu
- What is the proper method of using global $post?
- How to remove or add submenu item on plugin activate or deactive
- how to add stylesheet to particular plugin only?
- Difference between wp_salt schemes
- WordPress daily cron is executing more frequently than once a day
- How can I replace the search results displayed by WordPress?
- What is the best way to store a few fields?
- I18n not working in plugin
- Mixing l18n string from my plugin with WordPress’ translations
- Non editable custom taxonomy
- How to resize WordPress images on upload to specific height and width without cropping it
- Get section of input passed to the sanitize_callback
- Checking for existing title in custom db query not working
- Many Single Sites, One Plugin directory – adjust plugins_url()
- insufficient permissions; coding an action for plugin governed by custom capability
- My plugin creates custom widgets, How can I programatically add them to existing sidebar widget areas?
- Custom Endpoint – Does it possible to use PUT method with WP API Rest?
- How to know if current plugin is going to be used while rendering the page?
- Dynamically modify content added to table via javascript
- functions won’t fire after I converted my code from procedural code to OOP
- How to prevent wp_insert_post from creating a new post every second?
- CPT UI and custom database table
- Updating a WP Plugin SVN not showing on WordPress Website or Zip
- Download stopped working in 4.7.4
- $wpdb Mysql trigger problem
- edit-tags.php in plugin admin menu hides when is the active page
- WordPress postboxes On Tabbed Views and Hiding Registered Pages
- grouping my widgets wordpress
- Yet another wp_insert_post infinite loop. What is wrong?
- Initialize class inside plugin
- Why does this fail: Disabling plugins enqueue_script() in functions.php
- “Print to printer” functionality in a plugin
- Remove text from confirmation message
- Which subset of html does WordPress support?
- Can I use an array to create multiple tables?
- How to set init for maximum script execution, memory limit and max files upload in wordpress
- Display months on a drop down calendar as TEXT instead of Numbers