Last active
March 11, 2022 10:41
-
-
Save wpmudev-sls/159150f2b5b2fb195b5d405554528eee to your computer and use it in GitHub Desktop.
[Forminator Pro] - Custom Prefill shortcode
This file contains hidden or 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] - Custom Prefill shortcode | |
* Description: Adds the [wpmudev_forminator_form] which accepts custom prefill values passed as a discrete parameters, for example [wpmudev_forminator_form id="6" foo="bar" bar="baz"] | |
* Author: Anderson Salas @ WPMUDEV | |
* Task: SLS-3388 | |
* Author URI: https://premium.wpmudev.org | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) { | |
return; | |
} | |
add_shortcode( 'wpmudev_forminator_form', function( $atts = array() ) { | |
if ( empty( $atts['id'] ) ) { | |
return; | |
} | |
// Backup the $_GET/$_REQUEST data. | |
$base_get = $_GET; | |
$base_request = $_REQUEST; | |
$id = $atts['id']; | |
unset( $atts['id'] ); | |
foreach ( $atts as $name => $value ) { | |
$_GET[ $name ] = $value; | |
$_REQUEST[ $name ] = $value; | |
} | |
// NOTE: This only works if the target form has previously configured its | |
// "Pre-populate" field attributes. | |
$html = do_shortcode( sprintf( '[forminator_form id="%d"]', $id ) ); | |
// Restore the original data. | |
$_GET = $base_get; | |
$_REQUEST = $base_request; | |
return $html; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment