Skip to content

Instantly share code, notes, and snippets.

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 mitchelldmiller/38c7922cbfe381cde3ef3cf370ffbbe9 to your computer and use it in GitHub Desktop.
Save mitchelldmiller/38c7922cbfe381cde3ef3cf370ffbbe9 to your computer and use it in GitHub Desktop.
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