Created
March 29, 2022 15:53
-
-
Save jmarreros/41331f90a5f3bad9a520ef4718c501c9 to your computer and use it in GitHub Desktop.
Guarda el nombre del usuario enviado desde un formulario CF7 y lo imprime en una página
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 // No copiar esta línea | |
add_action( 'init', 'dcms_session_start' ); | |
function dcms_session_start() { | |
if ( ! session_id() ) { | |
session_start(); // Iniciamos la sesion | |
} | |
} | |
add_action( 'wpcf7_submit', 'dcms_action_wpcf7_submit', 10, 2 ); | |
function dcms_action_wpcf7_submit( $instance, $result ) { | |
$submission = WPCF7_Submission :: get_instance(); | |
$name = $submission->get_posted_data()['your-name']; | |
$_SESSION['contact-name'] = $name; // Establecemos un valor para la sesion | |
}; | |
add_filter( 'the_content', 'dcms_add_name_content'); | |
function dcms_add_name_content ( $content ) { | |
if ( is_page('mensaje') ) { | |
$name = $_SESSION['contact-name']??''; // Recuperamos el valor | |
return "Hola $name, $content"; | |
} | |
return $content; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment