Last active
February 22, 2024 08:50
-
-
Save wpmudev-sls/3f5bb6a097bbdd5cb94232575897e66c to your computer and use it in GitHub Desktop.
[Forminator Pro] - Redirection rule based on user role on form login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: [Forminator Pro] Redirection rule based on user role on form login | |
* Description: Redirection rule based on user role on form login | |
* Author: Prashant @ WPMUDEV | |
* Task: SLS-5786 | |
* Author URI: https://premium.wpmudev.org | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; // Exit if accessed directly. | |
} | |
add_filter( 'forminator_form_submit_response', 'wpmudev_redirect_user_redirect', 20, 2 ); | |
add_filter( 'forminator_form_ajax_submit_response', 'wpmudev_redirect_user_redirect', 20, 2 ); | |
function wpmudev_redirect_user_redirect( $response, $form_id ) { | |
if ( 1657 != $form_id ) { // Please change the form ID. | |
return $response; | |
} | |
$user_id = ! empty( $response['user_id'] ) ? $response['user_id'] : ''; | |
if ( ! empty ( $user_id ) ) { | |
$user_data = get_userdata( $user_id ); | |
if ( in_array( 'prelim_investors', $user_data->roles ) ) { | |
$response['url'] = home_url() . '/dev-investor-form/'; | |
} | |
if ( in_array( 'company', $user_data->roles ) ) { | |
$redirect_to = home_url() . '/dev-company-landing/'; | |
} | |
} | |
return $response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment