You can use update_user_meta()
to add information to a user’s meta fields, and count_user_posts()
to get an initial count.
So, for instance:
<?php
add_action( 'new_to_publish', 'wpse96358_author_count' );
add_action( 'draft_to_publish', 'wps396358_author_count' );
function wpse96358_author_count() {
global $post;
// get initial count
$single = true;
$author_count = get_user_meta( $post->post_author, 'author_count', $single );
if ( strlen( $author_count ) > 0 ) {
$author_count = intval( $author_count ); // make sure it's a number
$author_count++; // increment by one
} else {
// the meta information isn't set, so we'll create it
$author_count = count_user_posts( $post->post_author );
}
update_user_meta( $post->post_author, 'author_count', $author_count );
}
?>
NB
You would be wise to consult the Action Reference and the Post Status Transitions reference to see which action would work best for you. I picked new_to_publish
and draft_to_publish
but it depends on when you want the updates to happen.