Skip to content

Instantly share code, notes, and snippets.

@jmarreros
Created March 29, 2022 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmarreros/41331f90a5f3bad9a520ef4718c501c9 to your computer and use it in GitHub Desktop.
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
<?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