Modified to store $_GET info as $_SESSION info
-
Hi,
I have modified the script below to store the info in a session before to in case users move around a site before they return to a landing page.
Please find below:
add_action( ‘wpcf7_init’, ‘wpcf7_add_shortcode_getparam’ );
/* BOF: Script to use Sessions */
//Source: https://www.ads-software.com/support/topic/using-session-in-wordpress
add_action(‘init’, ‘myStartSession’, 1);
add_action(‘wp_logout’, ‘myEndSession’);
add_action(‘wp_login’, ‘myEndSession’);function myStartSession() {
if(!session_id()) {
session_start();
}
}function myEndSession() {
session_destroy ();
}
/* EOF: Script to use Sessions */function wpcf7_add_shortcode_getparam() {
if ( function_exists( ‘wpcf7_add_shortcode’ ) ) {
wpcf7_add_shortcode( ‘getparam’, ‘wpcf7_getparam_shortcode_handler’, true );
wpcf7_add_shortcode( ‘showparam’, ‘wpcf7_showparam_shortcode_handler’, true );
}
}function wpcf7_getparam_shortcode_handler($tag) {
if (!is_array($tag)) return ”;$name = $tag[‘name’];
if (empty($name)) return ”;if ($_GET[$name] == NULL) {
$html = ‘<input type=”hidden” name=”‘ . $name . ‘” value=”‘. esc_attr( $_SESSION[$name] ) . ‘” />’;
} else {
$_SESSION[$name] = $_GET[$name];
$html = ‘<input type=”hidden” name=”‘ . $name . ‘” value=”‘. esc_attr( $_GET[$name] ) . ‘” />’;
}return $html;
}function wpcf7_showparam_shortcode_handler($tag) {
if (!is_array($tag)) return ”;$name = $tag[‘name’];
if (empty($name)) return ”;$html = esc_html( $_GET[$name] );
return $html;
}https://www.ads-software.com/plugins/contact-form-7-get-and-show-parameter-from-url/
- The topic ‘Modified to store $_GET info as $_SESSION info’ is closed to new replies.