Title: Custom Function When Add User
Last modified: August 20, 2016

---

# Custom Function When Add User

 *  [BaseQuatro](https://wordpress.org/support/users/basequatro/)
 * (@basequatro)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/custom-function-when-add-user/)
 * Hi All,
 * Im searching all over codex, google and forum to create a custom function when
   adding users in wordpress, but im a new coder.
    Can anyone help me with this:
 * When creating a user, automaticly create a category with username, page with 
   username and custom template.
 * Im new to php and wordpress, dont know exactly were to add these functions.
 * lines 1593 – 1602 – wp-includes/users.php
 *     ```
       function wp_create_user($username, $password, $email = '') {
       	$user_login = esc_sql( $username );
       	$user_email = esc_sql( $email    );
       	$user_pass = $password;
   
               // create a category with username
       	wp_create_category( $username );
   
               // create page with username and theme?
               $my_page = array(
               'post_title' => '$username',
               'post_content' => '[list category=$username]',
               'post_status' => 'publish',
               'post_author' => 1,
               //didnt find this function above
               //'page_template' => 'portal.php',
         );
   
              // Insert the post into the database
                 wp_insert_post( $my_page );
   
       	$userdata = compact('user_login', 'user_email', 'user_pass');
       	return wp_insert_user($userdata);
       }
       ```
   
 * If someone can help me or have a better solution i buy a beer!
 * Thanks

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [BaseQuatro](https://wordpress.org/support/users/basequatro/)
 * (@basequatro)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/custom-function-when-add-user/#post-2438218)
 * Ended up with this, hope it helps someone.
 * Add to functions.php of your theme
 *     ```
       add_action('user_register','my_function');
   
       function my_function($user_id){
   
               $user_info = get_userdata($user_id);
               $username=$user_info->user_login;
   
               // create a category with username
            	wp_create_category( $username );
   
               // create page with username and theme?
   
               $my_page = array(
               'post_title' => $username,
               'post_content' => '[list category='/$username/']',
               'post_status' => 'publish',
       		'post_type' => 'page',
               'post_author' => 1,
       		'post_parent' => 105,
       		'post_status' => 'private',
       		 );
   
       		$newPageID = wp_insert_post( $my_page );
   
       		update_post_meta($newPageID, "_wp_page_template", "cliente-portal.php");
   
       }
       ```
   
 *  Thread Starter [BaseQuatro](https://wordpress.org/support/users/basequatro/)
 * (@basequatro)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/custom-function-when-add-user/#post-2438219)
 * now looking functions to remove category and page when deleting user…

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom Function When Add User’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [page](https://wordpress.org/support/topic-tag/page/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [user](https://wordpress.org/support/topic-tag/user/)

 * 2 replies
 * 1 participant
 * Last reply from: [BaseQuatro](https://wordpress.org/support/users/basequatro/)
 * Last activity: [14 years, 5 months ago](https://wordpress.org/support/topic/custom-function-when-add-user/#post-2438219)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
