Error Uncaught ArgumentCountError i cant find it

Your problem is how you’re using the wp_new_user_notification_email filter. As you’ll see from its documentation, the callback function receives 3 arguments:

  • $wp_new_user_notification_email
  • $user
  • $blogname

However, the function you’re using as the callback accepts 4 arguments.

function custom_wp_new_user_notification_email( 
 $wp_new_user_notification_email, $user, $blogname, $post ) {

Plus you’ve set the number of arguments to be passed to the callback to 5:

add_filter( 'wp_new_user_notification_email', 'custom_wp_new_user_notification_email', 10, 5 );

Your callback function needs to accept at least the same number of arguments passed you specify in the add_filter() call, and that number can’t be any more than passed by the original filter.

So update your add_filter() call to support all 3 arguments:

add_filter( 'wp_new_user_notification_email', 'custom_wp_new_user_notification_email', 10, 3 );

And then make sure custom_wp_new_user_notification_email() function only accepts those arguments:

function custom_wp_new_user_notification_email( 
 $wp_new_user_notification_email, $user, $blogname ) {

You’re also going to need to address your usage of $post in the custom_wp_new_user_notification_email() function. As I’ve shown, the wp_new_user_notification_email filter does not pass any $post object, but you’re using it frequently in your code. This doesn’t make any sense because the new user notification email has nothing to do with any post.

If you are creating a user when a post is published, as it appears, and then need to reference that post in the notification email, you’re going to need to do it a different way, because the new user email doesn’t know anything about this post.

One option would be to save the post ID as user meta post_id when the user is created, and then use the $user argument of the callback function to retrieve the value:

function custom_wp_new_user_notification_email( $wp_new_user_notification_email, $user, $blogname ) {
    $post_id = get_user_meta( $user->ID, 'post_id', true );
    $post    = get_post( $post_id );

    // etc.
}

Lastly, I can see that you’ve also attempted to hook this function into various post status transitions:

add_action('new_to_pending', 'custom_wp_new_user_notification_email');
add_action('draft_to_pending', 'custom_wp_new_user_notification_email');
add_action('auto-draft_to_pending', 'custom_wp_new_user_notification_email');

I don’t really know what you’re doing here, but you can’t use the same function as a filter on wp_new_user_notification_email on these hooks, because they take different arguments and do different things. If you want a function to run on these hooks, make a separate function with a different name.