• Resolved novaclever

    (@novaclever)


    Hello !

    When I use the bdpwr_code_email_text like this :

    add_filter( 'bdpwr_code_email_text' , function( $text , $email , $code , $expiry ) {
      $text = "Une réinitialisation du mot de passe a été demandée pour votre compte " . $email ." et votre code de réinitialisation du mot de passe est " . $code . ". \n Veuillez noter que ce code expirera à " . $expiry . ".";
      return $text;
    });

    I get a fatal error :

    2020/06/08 09:53:14 [error] 87451#87451: *9276 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in /www/my_website/public/wp-includes/class-wp-hook.php on line 289 and exactly 4 expected in /www/my_website/public/wp-content/themes/mytheme-child/functions.php:495
    Stack trace:
    #0 /www/my_website/public/wp-includes/class-wp-hook.php(289): {closure}('\n A password r...')
    #1 /www/my_website/public/wp-includes/plugin.php(206): WP_Hook->apply_filters('\n A password r...', Array)
    #2 /www/my_website/public/wp-content/plugins/bdvs-password-reset/inc/email/functions.php(57): apply_filters('bdpwr_code_emai...', '\n A password r...', 'michael...', '025371', 1591610294)
    #3 /www/my_website/public/wp-content/plugins/bdvs-password-reset/inc/class/class.user.php(53): bdpwr_send_password_reset_code_email('michael...', '025371', 1591610294)
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author dominic_ks

    (@dominic_ks)

    Hey,

    Thanks for that, yeah I had a feeling this would be the case when you mentioned it, I should update the examples, but the reason is that when you have a filter or hooked function receiving more than one parameter you need to assign a priority and specify the number of parameters, so in your case it’d be like this:

    add_filter( 'bdpwr_code_email_text' , function( $text , $email , $code , $expiry ) {
      $text = "Une réinitialisation du mot de passe a été demandée pour votre compte " . $email ." et votre code de réinitialisation du mot de passe est " . $code . ". \n Veuillez noter que ce code expirera à " . $expiry . ".";
      return $text;
    }, 10 , 4 );

    Note the priority 10 and specification of 4 parameters to be passed to the function.

    Also, FYI, the $expiry time that comes through here is a unix timestamp so still needs formatting. You could use your own time function here or the one that comes with the plugin:

    bdpwr_get_formatted_date( $expiry )

    So the complete code here would be:

    add_filter( 'bdpwr_code_email_text' , function( $text , $email , $code , $expiry ) {
      $text = "Une réinitialisation du mot de passe a été demandée pour votre compte " . $email ." et votre code de réinitialisation du mot de passe est " . $code . ". \n Veuillez noter que ce code expirera à " . $bdpwr_get_formatted_date( $expiry ). ".";
      return $text;
    }, 10 , 4 );

    Arguably that filter would be better if it passed the formatted time since there’s a separate filter for the format, but this should do what you need.

    Thread Starter novaclever

    (@novaclever)

    Yes I forgot about the priority and also to specify the number of parameters needed, thank you !

    If it can help other, here is my filter :

    add_filter( 'bdpwr_code_email_text' , function( $text , $email , $code , $expiry ) {
     $expiry_formatted = bdpwr_get_formatted_date( $expiry );
      $text = "Une réinitialisation du mot de passe a été demandée pour votre compte " . $email ." et votre code de réinitialisation du mot de passe est " . $code . ". \n Veuillez noter que ce code expirera à " . $expiry_formatted . ".";
      return $text;
    }, 10 , 4 );
    Plugin Author dominic_ks

    (@dominic_ks)

    Awesome, thanks for confirming.

    Also, I haven’t got to adding translation support for this plugin, but when I do, would you be interested in chipping in the French?

    Thanks,

    Thread Starter novaclever

    (@novaclever)

    Yes sure, let me know when you’ve added it, I’d be glad to help you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘bdpwr_code_email_text filter error’ is closed to new replies.