How do I repair the next fatal mistake?

How do I repair the next fatal mistake?

2 minutes, 48 seconds Read

Fatal error: non-argument counter: too few arguments to function update_user_meta (), 2 passed in/www/wp-content/plugins/custom-user-register-fields-tutor-lm /wordpress/wp-includes/user.php:129666666666666666666666666666666

Stack Trace:

#0 /www/wp-content/plugins/custom-user-registration-fields-tutor-lms/tutor-lms-custom-user-registration-fields.php(176): update_user_meta(43, '11/05/1995') 
#1 /wordpress/wp-includes/class-wp-hook.php(326): tutor_field_cif_add_custom_user_meta(43) #2 /wordpress/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) 
#3 /wordpress/wp-includes/plugin.php(517): WP_Hook->do_action(Array) 
#4 /wordpress/wp-includes/user.php(2621): do_action('user_register', 43, Array) 
#5 /www/wp-content/plugins/tutor/classes/Instructor.php(148): wp_insert_user(Array) 
#6 /wordpress/wp-includes/class-wp-hook.php(324): TUTOR\Instructor->register_instructor('') #7 /wordpress/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) 
#8 /wordpress/wp-includes/plugin.php(517): WP_Hook->do_action(Array) 
#9 /wordpress/wp-includes/template-loader.php(13): do_action('template_redire...') 
#10 /wordpress/wp-blog-header.php(19): require_once('/wordpress/wp-i...') 
#11 /www/index.php(17): require('/wordpress/wp-b...') 
#12 {main} thrown in /wordpress/wp-includes/user.php on line 1296

I recently added the following code to the functions.php part of my theme form editor to make a hook that makes a new message within my made CPT (members) when someone signs up using the ‘Tutor Registration’ form:

function create_cpt_on_user_registration( $user_id ) {
    // Get user data
    $user_info = get_userdata( $user_id );
    // Get the first and last name
    $first_name = $user_info->first_name;
    $last_name = $user_info->last_name;
    // Construct the post title with first and last name
    // Original: $post_title="New User Post: " . $first_name . ' ' . $last_name;
    $post_title = $first_name . ' ' . $last_name; // Edited to just first and last name
    // Construct the post content with first and last name
    $post_content="This post was created automatically for user: " . $first_name . ' ' . $last_name;
    // Define the post details for your CPT
    $post_data = array(
        'post_title'    => $post_title,
        'post_content'  => $post_content,
        'post_status'   => 'publish', // Or 'draft', 'pending' etc.
        'post_type'     => 'members', // The slug of your custom post type
        'post_author'   => $user_id  // Set the author of the new post to the new user
    );
    // Insert the post
    wp_insert_post( $post_data );
}
add_action( 'user_register', 'create_cpt_on_user_registration' );

I then added the code to a code filler to try to solve the problem, and it gave me the following code:

function create_cpt_on_user_registration( $user_id ) {
    // Get user data
    $user_info = get_userdata( $user_id );
    // Get the first and last name
    $first_name = $user_info->first_name;
    $last_name = $user_info->last_name;
    // Construct the post title with first and last name
    $post_title = $first_name . ' ' . $last_name;
    // Construct the post content with first and last name
    $post_content="This post was created automatically for user: " . $first_name . ' ' . $last_name;
    // Define the post details for your CPT
    $post_data = array(
        'post_title'    => $post_title,
        'post_content'  => $post_content,
        'post_status'   => 'publish', // Or 'draft', 'pending' etc.
        'post_type'     => 'members', // The slug of your custom post type
        'post_author'   => user_can( $user_id, 'publish_posts' ) ? (int) $user_id : 1
    );
    // Insert the post
    wp_insert_post( $post_data );
}
add_action( 'user_register', 'create_cpt_on_user_registration' );

This did not solve the problem either.

I can see that only 2 arguments are adopted when I believe it expects 12 (from the stacking trace). How can I solve this problem?

#repair #fatal #mistake

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *