Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
shortcode to add recipient's first name to Quick Mail email message
<?php
// quick-mail-first-name-shortcode.php
/**
* get first name of Quick Mail recipient.
* for shortcode to add recipient's first name to Quick Mail email message.
* @return string first name of recipient or email address. question mark is n/a.
* @see https://wheredidmybraingo.com/tag/quick-mail/ Quick Mail WordPress Plugin
* @see https://wordpress.org/support/topic/add-user-name-to-email/ support request
*/
function qm_get_first_name() {
$first = '?';
if ( empty( $_POST['qm-email']) ) {
return $first;
}
$text = urldecode( $_POST['qm-email'] );
$all = explode( ' ', $text );
$j = count( $all );
if ( 3 < $j ) {
$j = 3;
}
switch ( $j ) {
case 3: $first = substr( $all[0], 1 );
break;
case 2: $first = substr( $all[0], 1, -1 );
break;
default: $first = $all[0];
break;
} // end switch
return $first;
} // end qm_get_first_name
add_shortcode('first_name', 'qm_get_first_name');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.