title: wp_insert_post() not working when in loop
body: <p>I have a script which scrapes articles from the web and saves the url to a .txt file. I've created a custom plugin which on activation, loops through the urls and creates a draft post with the content being an embedded article. I'm using the following code in my plugin</p>
  <pre><code>&lt;?php
  register_activation_hook(__FILE__, 'my_plugin_activate');
  function my_plugin_activate(){
      my_plugin_install_site();
  }
  
  function my_plugin_install_site(){
      global $user_ID;
      $handle = fopen(&quot;listOfURLs.txt&quot;, &quot;r&quot;);
      if ($handle) {
          $count = 0;
          while (($line = fgets($handle)) !== false) {
              // process the line read.
              PostCreator('test', 'post', '&lt;iframe src=&quot;' . trim($line) . '&quot; class=&quot;alumni-embeded-page&quot;&gt;&lt;/iframe&gt;');
          }
          fclose($handle);
      }
      // PostCreator( 'test1', 'post', '&lt;iframe src=&quot;[link]&quot; class=&quot;alumni-embeded-page&quot;&gt;&lt;/iframe&gt;' );
      // PostCreator( 'test2', 'post', '&lt;iframe src=&quot;[link]&quot; class=&quot;alumni-embeded-page&quot;&gt;&lt;/iframe&gt;' );
  }
  
  function PostCreator(
      $name      = 'AUTO POST',
      $type      = 'post',
      $content   = 'DUMMY CONTENT',
      $category  = array(1,2),
      $template  = NULL,
      $author_id = '1',
      $status    = 'draft'
  ) {
      $post_data = array(
          'post_title'    =&gt; wp_strip_all_tags( $name ),
          'post_content'  =&gt; $content,
          'post_status'   =&gt; $status,
          'post_type'     =&gt; $type,
          'post_author'   =&gt; $author_id,
          'post_category' =&gt; $category,
          'page_template' =&gt; $template
      );
      $post_id = wp_insert_post($post_data); 
  }
  </code></pre>
  <p>The <em>listOfURLs.txt</em> file is simply a text file in the same directory with a link to an article on every line. I'm only using 5 links to test at the moment. The problem is currently the script does not create any posts when trying to use the loop. The PostCreator() method did work when I coded the method calls manually(as shown by the comments).</p>
  <p>I'm also getting the following error when activating the plugin. Not sure it's related as it was still displayed when hard coding the method calls.</p>
  <blockquote>
  <p>The plugin generated 205 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.</p>
  </blockquote>