Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save teolopez/5893997 to your computer and use it in GitHub Desktop.
Save teolopez/5893997 to your computer and use it in GitHub Desktop.
When a new user registers a new post is auto created and assigned to the new user as a draft.
// -----------------------------------------------------------------
// Add Post On New User Registration and Assign to User Registration
// -----------------------------------------------------------------
add_action( 'user_register', 'gamma_new_user_post' );
/**
* Add a new post when user registers.
*/
function gamma_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' => 'Testing auto post creation.',
'post_status' => 'draft',
'post_author' => $user_id,
'post_category' => array(1),
) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment