Skip Navigation

[Resuelto] cred_success_redirect breaks the redirect of other forms

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
Client is using the cred_success_redirect API hook for a custom redirect on certain forms, but it is breaking the redirect on all other forms.

Solution:
There was an error in the client code shown below. A filter must always return the first argument.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

This support ticket is created hace 6 años, 6 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Este tema contiene 3 respuestas, tiene 3 mensajes.

Última actualización por Zayne hace 6 años, 6 meses.

Asistido por: Nigel.

Autor
Mensajes
#905393

Hi,

I'm using the following code to redirect one of the forms:

add_filter('cred_success_redirect', 'custom_redirect', 10, 3);
function custom_redirect( $url, $post_id, $form_data ) {  
    if ($form_data['id']==49 || $form_data['id']==529) {
        $return_id = $_GET['returnid']; 
        $unit_id = $_GET['unitid']; 
        return get_permalink($return_id) . '?unitid=' . $unit_id;        
    } 
}

It works fine, but I noticed that the forms that are not listed in this snippet don't redirect according to their settings after I added this code. Removing it makes other forms redirect properly.

Is it supposed to be like that? Should I use cred_success_redirect_[form_id] for each form when I need to redirect only some of the them?

Thanks.

#905400

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

Hi Valeria

A filter must always return the first parameter (whether it has been modified or not).

Your function only returns anything for forms 49 and 529, for other forms it returns nothing.

You just need to add a line to return $url at the end.

#905414

That's right... Thanks, working now.

#1235230

Could you please post the final version of this code? I'm struggling to figure out where the final

return $url

should go.

Here's my snippet:

<?php

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

add_filter('cred_success_redirect_2873', 'redirect_to_parent', 10, 3);
function redirect_to_parent($url, $post_id, $form_data) {
  if ($form_data['id']==2873 || $form_data['id']==2896) {
    $parent_id = toolset_get_related_post($post_id, 'work-recording');
  	return get_permalink( $parent_id );
  }
  return $url
}