I added more variables to the default function of wordpress and I see this error. Any suggestions? Thanks in advance!!

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');
add_action('init', 'approve_post');

function set_html_content_type() { return 'text/html'; }

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

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

    // get author of post
$author = new WP_User($post->post_author);
 // create a key for security check and save as meta
$check = md5( $author->user_email . $post->ID  );
update_post_meta( $post->ID, '_approve_key', $check);
   // set the content for the email

    // create an url vor verify link with some variables: key, post id, and email
   $url = add_query_arg( 

  $check = md5( $author->user_email . $post->ID  );
   update_post_meta( $post->ID, '_approve_key', $check);
  $key = get_password_reset_key( $user );

 $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
 $message = sprintf(__('Bienvenido,')) . "\r\n\r\n";
 $message = "Tu cuenta:
  " . sprintf(__('%s'), $user->user_email) . "
  Para establecer la contraseña:
   " . "\r\n\r\n";

  $enlace1= "". network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . "\r\n" . "";

 $message .='<a href= "' . $url . '" onclick="window.open("' . $enlace1 . '" , \'_blank\', \'width=600,height=350\');" >Crear Contraseña</a>'. "\r\n";

$message .= "Saludos," . "\r\n";

 $wp_new_user_notification_email['message'] = $message;

return $wp_new_user_notification_email;


Error: Uncaught ArgumentCountError: Too few arguments to function custom_wp_new_user_notification_email(), 3 passed in ..


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.

  • 1
    Take a look at first 3 lines of his code - he’s assigning the same function for post status transition hooks also... – Krzysiek Dróżdż Mar 10 '19 at 6:21
  • Millions of thanks to both for their time. I've tried before posting it in other ways, I update the post. this works with exception to the href that calls in the function because it does not bring the variable $ url of the other function. Could you please have a look? – Jennifer Mar 10 '19 at 13:18
  • You should post a new question if you're experiencing a different issue. Your original question about the error has been answered. – Jacob Peattie Mar 10 '19 at 13:21
  • Good! Well I restore the original question and generate the new one.wordpress.stackexchange.com/questions/331232/… – Jennifer Mar 10 '19 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.