Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* VÍCTOR CAMPUZANO GALLEGO
- Simula la creación de campañas RSS con Sendinblue.
- Cada vez que se publica un nuevo post se envía el contenido HTML a Sendinblue por su API, generando una campaña para el día siguiente a las 12.00 am. Revisar parámetros.
- Requiere de una plantilla HTML que utilice los campos de sustitución.
- Requiere del fichero mailin.php de Sendinblue
- */
- // Función que se encarga de crear una campaña en Sendinblue cada vez que un post se ha publicado
- function post_published_sendinblue_campaign( $ID, $post ) {
- # ------------------
- # Create a campaign\
- # ------------------
- // Vamos a empezar con el contenido del mail
- $htmle = file_get_contents(__DIR__ . '/rss-template.html');
- // Construimos el array de búsquedas
- $s = array (
- '*|RSS_POST_TITLE|*',
- '*|RSS_POST_LINK|*',
- '*|RSS_POST_CONTENT|*',
- '*|RSS_POST_DATE|*',
- '*|RSS_POST_AUTHOR|*'
- );
- // Construimos el array de reemplazo
- $r = array (
- $post->post_title,
- get_permalink( $ID ),
- $post->post_content,
- date('d-m-Y',$post->post_date),
- get_the_author_meta( 'display_name', $post->post_author )
- );
- // hacemos los reemplazos
- $htmle = str_replace($s,$r,$htmle);
- # Include the SendinBlue library\
- require('mailin.php');
- # Instantiate the client\
- $mailin = new Mailin("https://api.sendinblue.com/v2.0","__SENDINBLUE_API_KEY");
- $data = array( "category"=>"__SENDINBLUE_CAMPAIGN_CATEGORY",
- "from_name"=>"__SENDINBLUE_FROM_NAME",
- "from_email"=>"__SENDINBLUE_FROM_EMAIL",
- "name"=>$post->post_title,
- "bat"=>"",
- "html_content"=>$htmle,
- "listid"=> array(2), // PLACE IDS OF LISTS TO SEND IT
- "scheduled_date"=>date("Y-m-d 12:00:00",strtotime('tomorrow')), // EDIT YOUR PREF. DATE TO SEND
- "subject"=>$post->post_title,
- "reply_to"=>"[DEFAULT_REPLY_TO]",
- "to_field"=>"[NOM] [PRENOM]",
- "inline_image"=>1,
- "mirror_active"=>1,
- "send_now"=>0,
- "utm_campaign"=>'RSSPosts'
- );
- # Make the call to the client\
- $resultado = $mailin->create_campaign($data);
- $to[] = '__NOTIFICATIONS_EMAIL';
- $subject = 'Sendinblue: '.$post->post_title;
- $message = sprintf ('Este es el resultado de programar la campaña del post %s en SendinBlue: %s.', $post->post_title, $resultado );
- $headers[] = '';
- wp_mail( $to, $subject, $message, $headers );
- }
- // Hook cuando un post se publica o su estado cambia a publicado
- add_action( 'publish_post', 'post_published_sendinblue_campaign', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement