Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Please do not edit core files, it can cause problems down the line. In addition, your changes could be lost with the next update.

    Try hooking the action ‘register_user’ and inserting your category from there.

    It’s moot when using hooks, but you shouldn’t need to require once taxonomy.php. It is loaded as part of the request to wp_-login.php.

    Thread Starter faidoc

    (@faidoc)

    I must be missing something now

    I’ve included this in my functions.php

    add_action('user_register', 'auto_create_category');
    
    function auto_create_category($user_id) {
    
        $category_fields = array('cat_name' => $_POST['first_name'],
    	'category_description' => '',
    	'category_nicename' => $_POST['first_name'],
    	'category_parent' => ''
    	);
    	$category_fields_id = wp_insert_category($category_fields);
    
    }

    But when I register a user, the screen goes white. The user is created, but fails creating the category

    Moderator bcworkz

    (@bcworkz)

    I see you corrected for my dyslexic “register_user”, sorry about that.

    Doesn’t appear to be the problem, but it’s a good idea to check if an array key exists in $_POST before trying to use it unless there is some javascript in place to ensure the field always has content.

    Actually, I’m not seeing the problem either. To get a better clue on what’s causing the blank white screen, define WP_DEBUG as true on wp-config.php, then do another test registration. Just don’t leave it as true for very long on a production site, it’s a small security risk.

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

The topic ‘Create category on user sign up’ is closed to new replies.