Created
May 14, 2017 17:29
-
-
Save mitchelldmiller/38c7922cbfe381cde3ef3cf370ffbbe9 to your computer and use it in GitHub Desktop.
shortcode to add recipient's first name to Quick Mail email message
This file contains 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 | |
// 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