write a post on user registration

Use the ‘user_register’ WordPress action to add the post function. Use wp_insert_post() to add the post.

add_action( 'user_register', 'wpse_99270_new_user_post' );
/**
 * Add a new post when user registers.
 */
function wpse_99270_new_user_post( $user_id ) {

    // Get user data.
    $user_data = get_userdata( $user_id );

    // Add new post here.
    wp_insert_post( array(
        'post_title'    => wp_strip_all_tags( sprintf( 'User %s has Joined %s', $user_data->user_login, get_bloginfo('name')  ) ),
        'post_content'  => 'Blah. Blah. Blah',
        'post_status'   => 'draft',
        'post_author'   => $user_id,
        'post_category' => array(1),
    ) );

}

Notes:

  • It would probably be a good idea to post the new post as a draft and have it approved before being published.
  • wp_strip_all_tags() is probably overkill.
  • This posts in the category with an ID of 1.

tech