Instead of using wp_mail
filter use action user_register
:
function fpw_new_user_post( $user_id ) {
global $wpdb;
update_user_meta( $user_id, $wpdb->base_prefix . 'capabilities', array( 'author' => TRUE ) );
$new_post = array (
'post_title' => 'User ' . get_user_by( 'id', $user_id )->user_login . ' registered @ ' . date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
'post_content' => 'This is my first post.',
'post_status' => 'publish',
'post_author' => $user_id,
'post_category' => array( 0 )
);
$post_id = wp_insert_post( $new_post );
if ( 0 == $post_id ) {
// do some error action
}
}
add_action( 'user_register', 'fpw_new_user_post', 10, 1 );
Based on an assumption that you want this user to publish other posts later, I’ve changed his role to author
. Of course you can set a new post to fit your needs.