You can use get_comments() function to retrieve comments by user_id or you can modify the below to also accept author_email or multiple authors. It will then only return the Comment IDs as an array and count them up, returning the integer which could be 0.
/**
* Count and return number of comments by User ID
*
* @param Integer $user_id - User ID of the wanted user
*
* @return Integer - Number of comments by given user
*/
function wpse284435_comment_count_by_author( $user_id ) {
$user_id = ( ! empty( $user_id ) ) ? intval( $user_id ) : get_current_user_id();
$comments = get_comments( array(
'fields' => 'ids',
'user_id' => $user_id,
) );
return count( $comments );
}
$comment_count = wpse284435_comment_count_by_author( 7 );
Related Posts:
- Check if add_menu_page exists or not
- Woocommerce hook after creating order? [closed]
- Disable /wp-admin/plugin-install.php
- What could a hacker do with my wp-config.php
- how to create child WordPress plugin
- How do I replace a function, declared inside a plugin’s class, in functions.php?
- What are the best practices for updating?
- How to disable core and plugin updates
- Removing the “Your backup folder MIGHT be visible to the public” Message Generated by the WP-DBManager Plugin
- Plugins not showing in dashboard->plugins section
- How to add favicon to my site – in both front end and admin panel
- TinyMCE Advanced newline problem
- Is there a plugin for posting inline comments, like in MS Word? [closed]
- Gutenberg: Error loading block: Invalid parameter(s): attributes but it can be used in the code
- Reordering themes in admin panel
- Does plugin uninstall always put WordPress back into original state?
- How do I email a new page password to somebody every month?
- Deactivate plugins only for mobile devices
- Drag-and-drop “Panels”-style visual layout editor?
- Plugins or Tutorials for displaying data from SQL-db on WP-page? [closed]
- Best way to diagnose which plug-ins/theme uses the most memory?
- How can I attach images to a post from the media library?
- Gutenberg: How to use output of php render_callback function in the block editors backend?
- Override Widget class in plugins with custom plugin
- How to prevent a function execution with another function?
- Custom database or Custom Post Types?
- How do I extract the Alt Text from an image attachment upload via the WordPress Options Framework Plugin?
- How to test a WordPress plugin through the upgrade automatically feature
- How can I list only sites that use a particular theme or plugin?
- Visual Composer vs. Advanced Custom Fields [closed]
- Disabled plugins are security holes – rumor or reality?
- Activating a single plugin via php
- Themes VS Plugins [duplicate]
- How to load plugin before the wordpress jquery?
- Failed to invoke other hook from the init hook
- Does Quantity of files in a plugin affect performance?
- Why is my ajax call refreshing the page?
- Add CSS class to add-to-cart button, Woocommerce [closed]
- How to count number of records found in a database table?
- Can a WordPress plugin or theme contain a virus?
- Is there an equivalent to Drupal’s Batch API in WordPress?
- Reblog from Tumblr to WordPress
- Plugin for Sending Email to Readers about New Posts? (besides “Subscribe2 “)
- Advanced Custom Fields query
- Is it possible to remove this action? (as it’s added just before it’s called)
- There’s some way to add a wrapper around posted images?
- Advanced Integration – WordPress + YOURLS
- How to redirect Old Post URL to new Post and keep Old post Comments?
- Redirect all blog links from WordPress.com site to new domain
- wp_enqueue_script fails to include in footer
- Automatically translating from existing .po and .mo files?
- What is the way to ship read-me strings like plugin-strings for internationalization?
- Plugin shortcode won’t work on a custom template file [closed]
- XML sitemap over product variations
- How to show popup to a group of users?
- Upload file inside plugins options page
- Plugin Expires Headers – W3 Total Cache [closed]
- Limit the number of plugins that can be installed in a WordPress installation
- Should WordPress plugins adhere to WordPress admin panel styling?
- How can we deal with unmaintained plugins with vulnerabilities?
- How to disable lightbox popup for “add a review” only?
- How to Sort the Favorite Plugins Screen Alphabetically?
- adding meta data using plugin to top of head
- Is there any way to get all the name or slug of template parts used in a page?
- how an array index could be a file path
- How can I make uploaded images in the editor load with HTTPS?
- How do i login when i cant access wp-login.php?
- First WordPress Plugin – Stat Issues
- MySql database help for a plugin
- How to checkout the wordpress.org plugin repository?
- Ultimate Member: Redirecting after registration
- Best method to upgrade multisite plugin’s numerous database table
- Activated plugin is stored as an object, rather than as a path
- Problem converting tags to categories while having large number of tags
- Adding an Options Page to a Plugin
- How do I “get the next 10 posts after post_id == x”?
- How to Delete all Unused photos Function
- how to create site exit messages with destination url displayed
- Magazine subscription sales through WP?
- Overriding functions in wordpress plugins
- Color java code the way it is colored in eclipse [closed]
- What is generating my meta og:description?
- Certain actions failing when run through cron
- How do you allow users tag a photo
- Updating the Drag-To-Share eXtended share URLs?
- List Category Posts rewrite necessitates rewrite of customised templates
- Changing “elapsed time” to “time remaining” on MP3-jPlayer audio player with CSS or PHP changes
- Send Custom welcome email to specific user group
- WordPress.org Plugin Directory doesn’t recognise screenshots [closed]
- How to check current user before all actions and filters?
- Ctrl+V images from clipboard into wordpress editor
- install robots.txt to wordpress website admin
- Send Contact form 7 data to remote server using .NET api [closed]
- Sending HTML emails via wp_mail not working properly
- WP Plugin for onpage link suggestions [closed]
- Customizing NEXTGEN Gallery To link images to pages
- add_action in static class [closed]
- Add content to footer – above wp_footer
- Automatically populate title field
- register_settings callback function posing problem