Pass Variables or Variable Place-Holder from Editor to PHP

I’m building a method for my client to construct a message content to be sent with wp_mail. Within that I’d like them to be able to choose variables, for example the message might look like this in my admin custom field:

Email: $email_address$

First Name: $first_name$

So that when I iterate over the lines I can spot a variable place-holder and replace $email_address$ with my variable so my PHP would look like:

$body = ‘Email Address: name@email.com<br>First Name: Mickey Mouse’;
wp_mail( $to, $subject, $body, $headers );

I suppose I’m wondering if there’s a particular or PHP-ish way to do this, I’m sure I’ve seen it in plugins before but don’t recall the exact formatting.

Read more here:: Pass Variables or Variable Place-Holder from Editor to PHP

Leave a Reply

Your email address will not be published. Required fields are marked *