WORDPRESS how to execute shortcode before sending an email and include the content in the message

0

I have the following problem. I need to develop a plugin for wordpress that at a given moment, personalizes and sends a series of emails to the user. The content of the emails is personalized in the administration with wp_editor, when saving, an option with the content in html is included in the bbdd. I have created several shortcodes that allow the personalization of the emails with some parameters so that the user can add them in the place they want the content of the email.

When I want to send the mail, I pick up the option referring to the content of the corresponding email and I save it in $ message, but when I receive the mail I see the shortcodes without executing.

How could I send the shortcodes executed in the mail? The shortcodes have html with specific data for each moment.

This is the text area code

if (isset($_POST['guardar_contenido_mails'])) {

    $datos_email_privada = $_POST['area_email_privada'];


    if ($allowEdit == true) {
        $datos_email_privada = update_option('contenido_emails_privada', $datos_email_privada);
    } else {
        $datos_email_privada = update_option('contenido_emails_privada', $datos_email_privada, null, 'no');
        wp_cache_delete('contenido_emails_privada');
    }
}
<div>
    <p>Este correo se envía al usuario cuando la inscripción depende de la aceptación de la administración</p>
        <?php 
            $settings = array(
                'textarea_rows' => 15,
                'tabindex' => 1,
                'wpautop' => false
                //'quicktags' => false
             );
             wp_editor($datos_email_privada, 'area_email_privada', $settings);
        ?>
</div>

This is my summary code, ignoring the header, to, etc .:

//Recojo los datos
$datos_email_privada = get_option('contenido_emails_privada', 'Personalice su contenido');

if ($tipo_mail == 'previo_validacion') {

    $message = $header_mail;
    $message .= '<div style="'.$separacion.'">';

    //Aquí incluyo el contenido del mail
    $message .= $datos_email_privada;

    $message .= '</div>';
    $message .= $footer_mail;

}

Before sending, I tried adding a filter to enable the shortcodes but it does not work

add_filter( 'wp_mail', 'do_shortcode' );


if (wp_mail($to, $subject, $message, $headers)) {
    return true;
};

Thank you very much in advance !!

Greetings

    
asked by Roberto Uknowmastilo García 26.02.2018 в 13:19
source

1 answer

1

I solved the issue thanks to this link.

link

By doing a do_shortcode ($ foo) when you bring the data, you convert the tags correctly.

//Aquí incluyo el contenido del mail
$message .= do_shortcode($datos_email_privada);

I hope it helps.

Greetings!

    
answered by 26.02.2018 в 15:49