Advertisement
Guest User

export_comments_to_bbpress

a guest
May 29th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.27 KB | None | 0 0
  1. /**
  2.      * Create bbPress replies with already existing comments
  3.      *
  4.      * @param int $post_id
  5.      * @param int $topic_id
  6.      */
  7.     function export_comments_to_bbpress ( $post_id, $topic_id, $topic_forum ) {
  8.        
  9.         /** getting post comments */
  10.         $post_comments = get_comments( array('post_id' => $post_id, 'order' => 'ASC'));
  11.        
  12.         if ( $post_comments ) {
  13.             foreach ( $post_comments as $post_comment ) {
  14.                
  15.                 if (! empty($post_comment->comment_type )) {
  16.                     continue;
  17.                 }
  18.                
  19.                 // If user is not registered
  20.                 if ( empty($post_comment->user_id) ) {
  21.                    
  22.                     //$post_comment->user_id = 107;
  23.                    
  24.                     // 1. Check if user exists by email
  25.                     if (! empty($post_comment->comment_author_email)) {
  26.                         $existing_user = get_user_by('email', $post_comment->comment_author_email);
  27.                        
  28.                         if ($existing_user)
  29.                             $post_comment->user_id = $existing_user->ID;
  30.                     }
  31.  
  32.                 }
  33.                
  34.                 // Reply data
  35.                 $reply_data = array(
  36.                     'post_parent'   => $topic_id, // topic ID
  37.                     'post_status'   => bbp_get_public_status_id(),
  38.                     'post_type'     => bbp_get_reply_post_type(),
  39.                     'post_author'   => $post_comment->user_id ,
  40.                     'post_content'  => $post_comment->comment_content ,
  41.                     'post_date'     => $post_comment->comment_date,
  42.                     'post_date_gmt' => $post_comment->comment_date_gmt,
  43.                     'post_modified' => $post_comment->comment_date,
  44.                     'post_modified_gmt' => $post_comment->comment_date_gmt
  45.                 );
  46.                
  47.                 // Reply meta
  48.                 $reply_meta = array(
  49.                     'author_ip' => $post_comment->comment_author_IP ,
  50.                     'forum_id'  => $topic_forum,
  51.                     'topic_id'  => $topic_id,
  52.                 );
  53.                
  54.                 // If not registered user, add anonymous user information
  55.                 if ( empty( $post_comment->user_id )) {
  56.                     // Parse args
  57.                     $anonymous = array(
  58.                         'anonymous_name' => $post_comment->comment_author,
  59.                         'anonymous_email'=> $post_comment->comment_author_email,
  60.                         'anonymous_website' => $post_comment->comment_author_url
  61.                     );
  62.                     $reply_meta = wp_parse_args( $reply_meta, $anonymous );
  63.                 }
  64.                
  65.                 $reply_id = bbp_insert_reply( $reply_data, $reply_meta );
  66.                
  67.                 $topic_permalink = bbp_get_topic_permalink($topic_id);
  68.                
  69.                 if ( ! empty($post_comment->comment_author_email) ) {
  70.                    
  71.                     $post_link = get_permalink( $post_comment->comment_post_ID );
  72.                     $post_title = get_the_title( $post_comment->comment_post_ID );
  73.                    
  74.                     $message = "<p>¡Hola, $post_comment->comment_author! Queremos informarte de que estamos mejorando Cuidado Infantil y hemos trasladado el comentario que hiciste en el artículo <a href='$post_link' target='_blank'>$post_title</a> al nuevo foro de la web, en el cual puedes hablar con otros usuarios sobre cualquier duda que tengas en el cuidado de tu bebé o niño.</p><p>Puedes encontrar tu comentario y otros relacionados pulsando sobre este enlace: <a href='$topic_permalink' target='_blank'>$topic_permalink</a></p><p>Además, si te registras, tendrás la posibilidad de conocer otras mamás o papás de niños de la edad del tuyo con los que, seguro, aprenderás consejos nuevos cada día.</p><br /><p>¡Un fuerte abrazo!<br /><b>El equipo de Cuidado Infantil</b></p>";
  75.                    
  76.                     wp_mail($post_comment->comment_author_email, 'Sobre tu comentario en Cuidado Infantil', $message);
  77.                 }
  78.                
  79.                
  80.                
  81.             }
  82.         }
  83.        
  84.        
  85.        
  86.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement