SNIPPET · GRATUITO
Aggiungi la pagina di provenienza alle email Gravity Forms
Mostra nelle notifiche Gravity Forms la pagina da cui è stato inviato il modulo.
A cosa serve
Se lo stesso form compare su più pagine, aggiunge alla notifica l’URL della pagina da cui è stato inviato. Usa prima source_url salvato da Gravity Forms e, se non disponibile, prova il referrer HTTP.
Requisito: Gravity Forms. La notifica deve contenere il merge tag {all_fields}.
Come usarlo
- Installa Code Snippets.
- Crea uno snippet PHP.
- Incolla il codice e attivalo.
/**
* Add the form source page after {all_fields} in Gravity Forms notifications.
*
* Uses the entry source_url when available and falls back to the HTTP referrer.
*/
add_filter( 'gform_notification', function ( $notification, $form, $entry ) {
if ( empty( $notification['message'] ) || strpos( $notification['message'], '{all_fields}' ) === false ) {
return $notification;
}
$source_url = '';
if ( is_array( $entry ) && ! empty( $entry['source_url'] ) ) {
$source_url = esc_url_raw( $entry['source_url'] );
}
if ( ! $source_url && ! empty( $_SERVER['HTTP_REFERER'] ) ) {
$source_url = esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) );
}
if ( $source_url ) {
$source_html = sprintf(
'<hr><p><strong>%s</strong> <a href="%s">%s</a></p>',
esc_html__( 'Source page:', 'mrc-snippets' ),
esc_url( $source_url ),
esc_html( $source_url )
);
} else {
$source_html = '<hr><p><strong>' .
esc_html__( 'Source page:', 'mrc-snippets' ) .
'</strong> ' .
esc_html__( 'Unavailable', 'mrc-snippets' ) .
'</p>';
}
$notification['message'] = str_replace(
'{all_fields}',
'{all_fields}' . $source_html,
$notification['message']
);
return $notification;
}, 10, 3 );
Come usarlo
- Installa Code Snippets Free su WordPress.
- Crea un nuovo snippet PHP.
- Copia e incolla il codice.
- Attivalo nell’ambito indicato.
È un metodo semplice, non obbligatorio: puoi integrare il codice nel tuo plugin o nel punto appropriato. Per gli esempi Gravity Forms configura gli ID e gli eventuali provider prima di attivare.