Skip Navigation

[Gelöst] How to customize error messages of the Toolset login and reset password links?

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
How can I customize the error or success messages of the Toolest login, reset passwords and so on forms?

Solution:
You can use the Custom Filter

wpv_filter_override_auth_errors

Example:

add_filter( 'wpv_filter_override_auth_errors', 'custom_wpv_override_auth_errors', 30, 3 );
function custom_wpv_override_auth_errors( $message, $class = '', $code = '' ) {
  switch( $code ) {
    case 'invalid_key';
    $message = __( 'CUSTOM VALUE', 'wpv-views' );
    break;
    case 'invalidcombo';
    $message = __( 'CUSTOM VALUE', 'wpv-views' );
    break;
  }
return $message;
}

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_override_auth_errors

This support ticket is created vor 6 Jahre, 8 Monate. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 13 Antworten, has 2 Stimmen.

Last updated by marcB-6 vor 6 Jahre, 7 Monate.

Assisted by: Beda.

Author
Artikel
#563784
Screenshot_13.png

I need to display custom message on sign-in page as per my code..So I have used filter mentioned here : https://toolset.com/forums/topic/wpv_filter_override_auth_errors-fires-not-just-for-errors/

I have added extra switch case

case 'inactive_account':
            $message .= __( 'Your account is Inactive.Please contact the ICISA supportdesk at support@icisa.org.', 'wpv-views' );
            break;

for my error message as mentioned below..

add_filter( 'wpv_filter_override_auth_errors', 'custom_wpv_override_auth_errors', 30, 3 );
function custom_wpv_override_auth_errors( $message, $class = '', $code = '' ) {
    
   if ( $code != '') {
    
    $message = __( '<strong>ERROR</strong>: ', 'wpv-views' );
         
    switch( $code ) {
        case 'invalid_username':
            $message .= __( 'Invalid username.', 'wpv-views' );
            break;
        case 'incorrect_password':
            $message .= __( 'The password you entered is incorrect.', 'wpv-views' );
            break;
        case 'empty_password':
            $message .= __( 'The password field is empty.', 'wpv-views' );
            break;
        case 'empty_username':
            $message .= __( 'The username field is empty.', 'wpv-views' );
            break;
        case 'inactive_account':
            $message .= __( 'Your account is Inactive.Please contact the ICISA supportdesk at support@icisa.org.', 'wpv-views' );
            break;
        default:
            $message .= __( 'Unknown error.', 'wpv-views' );
            break;
    }
    if( !empty( $class ) ) {
        $message = '<div class="' . $class . '">' . $message . '</div>';
    }
    return $message;
   }
}

It works fine for my custom message but, It is creating problem with success message on forgot password/reset password..It is displaying "ERROR: Unknown error." for success messages..Please check attached screenshot for the same.

Thanks

#563815

I see the error.

The variable $code returns "confirm" in this case - and that is the URL parameter added for example after a successful Forgot Password action.

It gets what $_REQUEST['fail_reason'] returns.

Why exactly $_REQUEST['fail_reason'] returns also "confirm", I am not sure, if this is a Problem in WordPress itself (I will investigate this).

It seems that this is due to the WordPress particular $_REQUEST global.
Since our Code gets the $code from the $_REQUEST, and that is not empty when such a request (get or post) exists, it fires the code always.

You can - for now - avoid this by adding conditions to your filter.
You do not want it to happen as example on the request "confirm", so this must be added to the code below:

if ( $code != '') {

Each possible request where you do not want the errors to apply, you need to add to the IF.
This looks like this:

if ( ($code != 'confirm')  && ($code != '')  ) {

I will check with the Developers if we can do something to make this easier.

#563831
actual_message.png
notshowingmessage.png

Hi Beda,

As you mentioned I have changed my condition, Now I don't see "ERROR:Unknown error" but, one more issue I see is that it is not displaying the actual message which is "Check your email for the confirmation link." default message from CRED.

I am going to attach two screenshots for errors.

1) It is not showing any message for : "forgot-password/?checkemail=confirm" after adding condition

if ( ($code != 'confirm')  && ($code != '')  ) {

2) Actual message which should be displayed for "forgot-password/?checkemail" is "Check your email for the confirmation link."

I can only see the Actual message if I remove the wpv_filter_override_auth_errors filter.

Thanks

#564645

I am investigating this with the Team and we will eventually escalate this to the Developers for further attention or update the DOC if needed.

I will update you here As soon I have a valid solution.

#564746

Thanks Beda...I am looking forward to solution as soon as possible.

#565095

I have found several solutions to this.

One is to reset the $code in your filter to listen to wpv_error:

function custom_wpv_override_auth_errors( $message, $class = '', $code = '' ) {
   $code = $_REQUEST['wpv_error'];
   if ( isset($code)) {//etc your code here

Another chance is to add a case "confirm" to the Custom Filter:

case 'confirm':
            $message .= __( 'Check your email', 'wpv-views' );
            break;

I am consulting with the DEV what is expected, what we want to allow, and then we will update the DOC as well.

#565105

I have put below code as you mentioned in last post
1) One is to reset the $code in your filter to listen to wpv_error:

function custom_wpv_override_auth_errors( $message, $class = '', $code = '' ) {
   $code = $_REQUEST['wpv_error'];
   if ( isset($code)) {//etc your code here

but it doesn't seems to be working..I can't see success message

2)

 case 'confirm':
            $message .= __( 'Check your email', 'wpv-views' );
            break; 

This will only work for 'confirm'...What about success messages from the Toolset in forgot/reset password forms?..They wont work

Thanks

#565130

Yes, that is why I am discussing with the DEV.

The messages cases seem to need to be re-added, all.
And that is not good.

I will update you in short.

#566407

Any Update??

#566717

Yes, there seem to be several issues you reported here, and some, to me seem expected.

We have Login, Reset, and Forgot Forms.

On login forms the code to me seems to work perfectly fine. Can you confirm this?

On the Forgot Form, I was able to make it work fine by adding more cases, and making sure the $code is not empty

if ( $code != ''){
  case 'confirm':
            $message .= __( 'SUCCESS', 'wpv-views' );
            break;
//etc

I also added a Custom message for the case when the Password Forgot form is submitted with a invalid User name:

case 'invalidcombo':
        	$message .= __( 'invalid username', 'wpv-views' );
            break;

That, for me, solved all issues.

You mention "This will only work for 'confirm'...What about success messages from the Toolset in forgot/reset password forms?..They wont work"

This is the Toolset Forgot Password Forms.

The reset form will eventually return other URL cases, that need to be added to the filter.

Generally, I cannot replicate a BUG as long I add the cases to the filter, but the problem is, this should not happen, IMHO; we should not need to add all cases, just because we need to customize one.

I will update you here ASAP.

#566729

On login forms the code to me seems to work perfectly fine. Can you confirm this?
Ans : Yes

Can you provide me possible switch cases for Login, Reset, and Forgot Forms? So I can put it for now to make it work..
And later on when you update here I will put that.

Thanks

#566730

Well, until now I saw invalid_key, confirm, invalidcombo.

But there might be more combinations. I will update here.

#566757

After more tests, I can solve the issues when I use the filter like this:

add_filter( 'wpv_filter_override_auth_errors', 'custom_wpv_override_auth_errors', 30, 3 );
function custom_wpv_override_auth_errors( $message, $class = '', $code = '' ) {
  switch( $code ) {
    case 'invalid_key';
    $message = __( 'CUSTOM VALUE', 'wpv-views' );
    break;
    case 'invalidcombo';
    $message = __( 'CUSTOM VALUE', 'wpv-views' );
    break;
  }
return $message;
}

This will target only the cases we want and if nothing is customized of course it will just return the core values from Views.

Does this work for you as well? I have tested it on several cases.
Now, there is a long list of possible cases, which I will try to document soon.
And of course, pass here in the ticket,

#566794

Thanks Beda
It is working for me

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.