Advertisement
vcgs

SENDINBLUE RSS CAMPAIGN SIMULATION

Aug 8th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.66 KB | None | 0 0
  1. /* VÍCTOR CAMPUZANO GALLEGO
  2. Simula la creación de campañas RSS con Sendinblue.
  3. 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.
  4. Requiere de una plantilla HTML que utilice los campos de sustitución.
  5. Requiere del fichero mailin.php de Sendinblue
  6. */
  7.  
  8. // Función que se encarga de crear una campaña en Sendinblue cada vez que un post se ha publicado
  9. function post_published_sendinblue_campaign( $ID, $post ) {
  10.     # ------------------
  11.    # Create a campaign\
  12.    # ------------------
  13.    
  14.     // Vamos a empezar con el contenido del mail
  15.     $htmle = file_get_contents(__DIR__ . '/rss-template.html');
  16.    
  17.     // Construimos el array de búsquedas
  18.     $s = array (
  19.         '*|RSS_POST_TITLE|*',
  20.         '*|RSS_POST_LINK|*',
  21.         '*|RSS_POST_CONTENT|*',
  22.         '*|RSS_POST_DATE|*',
  23.         '*|RSS_POST_AUTHOR|*'
  24.     );
  25.    
  26.     // Construimos el array de reemplazo
  27.     $r = array (
  28.         $post->post_title,
  29.         get_permalink( $ID ),
  30.         $post->post_content,
  31.         date('d-m-Y',$post->post_date),
  32.         get_the_author_meta( 'display_name', $post->post_author )
  33.     );
  34.    
  35.     // hacemos los reemplazos
  36.     $htmle = str_replace($s,$r,$htmle);
  37.    
  38.    
  39.     # Include the SendinBlue library\
  40.    require('mailin.php');
  41.  
  42.     # Instantiate the client\
  43.    $mailin = new Mailin("https://api.sendinblue.com/v2.0","__SENDINBLUE_API_KEY");
  44.    
  45.     $data = array( "category"=>"__SENDINBLUE_CAMPAIGN_CATEGORY",
  46.         "from_name"=>"__SENDINBLUE_FROM_NAME",
  47.         "from_email"=>"__SENDINBLUE_FROM_EMAIL",
  48.         "name"=>$post->post_title,
  49.         "bat"=>"",
  50.         "html_content"=>$htmle,
  51.         "listid"=> array(2), // PLACE IDS OF LISTS TO SEND IT
  52.         "scheduled_date"=>date("Y-m-d 12:00:00",strtotime('tomorrow')), // EDIT YOUR PREF. DATE TO SEND
  53.         "subject"=>$post->post_title,
  54.         "reply_to"=>"[DEFAULT_REPLY_TO]",
  55.         "to_field"=>"[NOM] [PRENOM]",
  56.         "inline_image"=>1,
  57.         "mirror_active"=>1,
  58.         "send_now"=>0,
  59.         "utm_campaign"=>'RSSPosts'
  60.       );
  61.  
  62.     # Make the call to the client\
  63.    $resultado = $mailin->create_campaign($data);
  64.     $to[] = '__NOTIFICATIONS_EMAIL';
  65.     $subject = 'Sendinblue: '.$post->post_title;
  66.     $message = sprintf ('Este es el resultado de programar la campaña del post %s en SendinBlue: %s.', $post->post_title, $resultado );
  67.     $headers[] = '';
  68.     wp_mail( $to, $subject, $message, $headers );
  69. }
  70. // Hook cuando un post se publica o su estado cambia a publicado
  71. add_action( 'publish_post', 'post_published_sendinblue_campaign', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement