Variable redirect on User Registration
-
Hey,
So, I have a Forminator regsitration form that I want to change the redirect URL of, depending on the URL variable
I copied and changed this code thinking it would work:
<?php /** * Plugin Name: [Forminator] - Custom Form Redirect * Plugin URI: https://wpmudev.com/ * Description: Adds custom redirect to Forms based on submitted data * Task: SLS-183 * Version: 1.0.0 * Author: Panos Lyrakis @ WPMUDEV * Author URI: https://wpmudev.com/ * License: GPLv2 or later */ if ( ! defined( 'ABSPATH' ) ) { exit; } if ( defined( 'WP_CLI' ) && WP_CLI ) { return; } if ( ! class_exists( 'WPMUDEV_Forminator_CustomForm_Redirect' ) ) { class WPMUDEV_Forminator_CustomForm_Redirect { private $form_id = 380; private static $_instance = null; public static function get_instance() { if( is_null( self::$_instance ) ){ self::$_instance = new WPMUDEV_Forminator_CustomForm_Redirect(); } return self::$_instance; } private function __construct() { add_filter( 'forminator_custom_form_submit_response', array( $this, 'handle_response' ), 20, 2 ); add_filter( 'forminator_custom_form_ajax_submit_response', array( $this, 'handle_response' ), 20, 2 ); } public function handle_response( $response, $form_id ) { if ( ! $this->is_valid_form( $form_id ) ) { return $response; } if( isset( $response['url'] ) ){ $response['url'] = $this->calc_url( $response['url'] ); } return $response; } private function calc_url( $redirect_url ) { $new_url = get_bloginfo('url').'/checkout'; if(isset($_GET['redirect_to']) && $_GET['redirect_to'] == $new_url) { $redirect_url = esc_url($new_url); } return $redirect_url; } private function is_valid_form( $form_id ) { return (int) $form_id === $this->form_id; } } if ( ! function_exists( 'wpmudev_forminator_customform_redirect' ) ) { function wpmudev_forminator_customform_redirect(){ return WPMUDEV_Forminator_CustomForm_Redirect::get_instance(); }; add_action( 'plugins_loaded', 'wpmudev_forminator_customform_redirect', 99 ); } }
The bit I edited is the
calc_url()
function, as that’s the bit in the original code that did the redirect URL change (I think)The login/reg page has the URL variable
?redirect_to=https://mydomainnamehere.com/checkout
on the end which is needed for something else and can’t be removedBasically, I want the form with
ID = 380
to redirect to that URL variable, but ONLY if it is present (hence the if statement in my calc_url() change aboveCan anyone see why this isn’t working?
- The topic ‘Variable redirect on User Registration’ is closed to new replies.