Support » Plugin: Admin Commenters Comments Count » Add to user metadata

Viewing 1 replies (of 1 total)
  • Plugin Author Scott Reilly

    (@coffee2code)

    WordPress & Plugin Developer

    @imscenterprise : Hi,

    It’s doable with some custom code since it’s not a built-in feature of the plugin.

    The following code can be put into a .php file in wp-content/mu-plugins/, or less ideally in your theme’s functions.php file.

    /**
     * Just before an export takes place, store all user comments counts in the
     * 'accc_comments_count' usermeta field.
     */
    function store_user_comment_counts_in_meta() {
    	// Don't do anything if Admin Commenters Comments Count isn't active.
    	if ( ! class_exists( 'c2c_AdminCommentersCommentsCount' ) ) {
    		return;
    	}
    
    	// Loop through all users.
    	foreach ( get_users() as $user ) {
    		// Get the count of the user's number of comments.
    		$comments_count = c2c_AdminCommentersCommentsCount::get_comments_count( 'comment_author_email', $user->user_email, 'comment', $user->ID );
    		// c2c_AdminCommentersCommentsCount::get_comments_count() returns an array that includes the number of
    		// approved comments and the number of pending comments. This next line presumes you only want the count
    		// of approved comments.
    		$comments_count = $comments_count[0];
    		// Store that count in user meta.
    		update_user_meta( $user->ID, 'accc_comments_count', $comments_count );
    	}
    }
    add_action( 'export_wp', 'store_user_comment_counts_in_meta' );

    I tested it out and it worked for me.

Viewing 1 replies (of 1 total)
  • The topic ‘Add to user metadata’ is closed to new replies.