Advertisement
JayHoffmann

Import Dummy Content and Post Thumbnails

Mar 28th, 2013
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.31 KB | None | 0 0
  1. <?php
  2. /*
  3. Here's all the content that will be inserted into the Looplet Custom Post Type
  4. Content from http://www.fillerati.com/
  5. Feel free to change as desired!
  6. */
  7.  
  8. $post1 = array( 'ID'=>3001, 'post_title' => 'When Ahab Fought the Whale', 'post_content' => '<p>Slowly wading through the meadows of brit, the Pequod still held on her way north-eastward towards the island of Java; a gentle air impelling her keel, so that in the surrounding serenity her three tall tapering masts mildly waved to that languid breeze, as three mild palms on a plain. And still, at wide intervals in the silvery night, the lonely, alluring jet would be seen.</p><p>But one transparent blue morning, when a stillness almost preternatural spread over the sea, however unattended with any stagnant calm; when the long burnished sun-glade on the waters seemed a golden finger laid across them, enjoining some secrecy; when the slippered waves whispered together as they softly ran on; in this profound hush of the visible sphere a strange spectre was seen by Daggoo from the main-mast-head.</p><p>In the distance, a great white mass lazily rose, and rising higher and higher, and disentangling itself from the azure, at last gleamed before our prow like a snow-slide, new slid from the hills. Thus glistening for a moment, as slowly it subsided, and sank. Then once more arose, and silently gleamed. It seemed not a whale; and yet is this Moby Dick? thought Daggoo. Again the phantom went down, but on re-appearing once more, with a stiletto-like cry that startled every man from his nod, the negro yelled out&mdash; - There! there again! there she breaches! right ahead! The White Whale, the White Whale! - </p>', 'post_status' => 'publish', 'post_type' => 'looplet', );
  9.  
  10. $post2 = array( 'post_title' => 'Orson Wells Really Pulled One Over', 'post_content' => '<p>My brother immediately grasped the situation, shouted, and hurried towards the struggle.  One of the men desisted and turned towards him, and my brother, realising from his antagonists face that a fight was unavoidable, and being an expert boxer, went into him forthwith and sent him down against the wheel of the chaise.</p><p>It was no time for pugilistic chivalry and my brother laid him quiet with a kick, and gripped the collar of the man who pulled at the slender lady\'s arm.  He heard the clatter of hoofs, the whip stung across his face, a third antagonist struck him between the eyes, and the man he held wrenched himself free and made off down the lane in the direction from which he had come.</p><p>Partly stunned, he found himself facing the man who had held the horse\'s head, and became aware of the chaise receding from him down the lane, swaying from side to side, and with the women in it looking back.  The man before him, a burly rough, tried to close, and he stopped him with a blow in the face.  Then, realising that he was deserted, he dodged round and made off down the lane after the chaise, with the sturdy man close behind him, and the fugitive, who had turned now, following remotely.</p><p>Suddenly he stumbled and fell; his immediate pursuer went headlong, and he rose to his feet to find himself with a couple of antagonists again.  He would have had little chance against them had not the slender lady very pluckily pulled up and returned to his help.  It seems she had had a revolver all this time, but it had been under the seat when she and her companion were attacked.  She fired at six yards\' distance, narrowly missing my brother.  The less courageous of the robbers made off, and his companion followed him, cursing his cowardice.  They both stopped in sight down the lane, where the third man lay insensible.</p>', 'post_status' => 'publish', 'post_type' => 'looplet', );
  11.  
  12. $post3 = array( 'post_title' => 'Toto the Hero!', 'post_content' => '<p>Finally she picked up her basket.</p><p>\"Come along, Toto," she said.  "We will go to the Emerald City and ask the Great Oz how to get back to Kansas again."</p><p>She closed the door, locked it, and put the key carefully in the pocket of her dress.  And so, with Toto trotting along soberly behind her, she started on her journey.</p>', 'post_status' => 'publish', 'post_type' => 'looplet', );
  13.  
  14. $post4 = array( 'post_title' => 'Alice, I Think You\'re Lost',
  15.     'post_content' => '<p>He took me for his housemaid, she said to herself as she ran. How  surprised hell be when he finds out who I am! But Id better take him  his fan and gloves&mdash;that is, if I can find them. As she said this, she  came upon a neat little house, on the door of which was a bright brass  plate with the name W. RABBIT engraved upon it. She went in without  knocking, and hurried upstairs, in great fear lest she should meet the  real Mary Ann, and be turned out of the house before she had found the  fan and gloves.</p><p>How queer it seems, Alice said to herself, \'to be going messages for  a rabbit! I suppose Dinahll be sending me on messages next! And she  began fancying the sort of thing that would happen: "Miss Alice! Come  here directly, and get ready for your walk!" "Coming in a minute,  nurse! But Ive got to see that the mouse doesn\'t get out." Only I don\'t  think, Alice went on, that they\'d let Dinah stop in the house if it  began ordering people about like that!</p>',
  16.     'post_status' => 'publish',
  17.     'post_type' => 'looplet',
  18. );
  19.  
  20. $post5 = array(
  21.     'post_title' => 'John Carter Bleeds Red and Green',
  22.     'post_content' => '<p>I am a very old man; how old I do not know.  Possibly I am a hundred, possibly more; but I cannot tell because I have never aged as other men, nor do I remember any childhood.  So far as I can recollect I have always been a man, a man of about thirty.  I appear today as I did forty years and more ago, and yet I feel that I cannot go on living forever; that some day I shall die the real death from which there is no resurrection.  I do not know why I should fear death, I who have died twice and am still alive; but yet I have the same horror of it as you who have never died, and it is because of this terror of death, I believe, that I am so convinced of my mortality.</p>',
  23.     'post_status' => 'publish',
  24.     'post_type' => 'looplet',
  25. );
  26.  
  27. $post6 = array(
  28.     'post_title' => 'Edwin and the Plague',
  29.     'post_content' => '<p>Hoo-Hoo, lying on his stomach and idly digging his toes in the sand,  cried out and investigated, first, his toe-nail, and next, the small  hole he had dug. The other two boys joined him, excavating the sand  rapidly with their hands till there lay three skeletons exposed. Two  were of adults, the third being that of a part-grown child. The old man  hudged along on the ground and peered at the find.</p><p>"Plague victims," he announced. "That\'s the way they died everywhere  in the last days. This must have been a family, running away from the  contagion and perishing here on the Cliff House beach. They&mdash;what are  you doing, Edwin?"</p>
  30. <p>This question was asked in sudden dismay, as Edwin, using the back of  his hunting knife, began to knock out the teeth from the jaws of one of  the skulls.</p>',
  31.     'post_status' => 'publish',
  32.     'post_type' => 'looplet',
  33. );
  34.  
  35. $post7 = array(
  36.     'post_title' => 'Eighy Days, Twenty Thousand Pounds',
  37.     'post_content' => '<p>Passepartout did not change countenance on hearing this name.  He thought that the time had not yet arrived to divulge to his master what had taken place between the detective and himself; and, in the account he gave of his absence, he simply excused himself for having been overtaken by drunkenness, in smoking opium at a tavern in Hong Kong.</p><p>Mr. Fogg heard this narrative coldly, without a word; and then furnished his man with funds necessary to obtain clothing more in harmony with his position.  Within an hour the Frenchman had cut off his nose and parted with his wings, and retained nothing about him which recalled the sectary of the god Tingou.</p>',
  38.     'post_status' => 'publish',
  39.     'post_type' => 'looplet',
  40. );
  41.  
  42. $post8 = array(
  43.     'post_title' => 'Had Perry Been Dead',
  44.     'post_content' => '<p>I felt that I was a fool ever to have attempted to escape alone, especially in view of the fact that our plans were already well formulated to make a break for freedom together.  Of course I realized that the chances of the success of our proposed venture were slim indeed, but I knew that I never could enjoy freedom without Perry so long as the old man lived, and I had learned that the probability that I might find him was less than slight.</p><p>Had Perry been dead, I should gladly have pitted my strength and wit against the savage and primordial world in which I found myself.  I could have lived in seclusion within some rocky cave until I had found the means to outfit myself with the crude weapons of the Stone Age, and then set out in search of her whose image had now become the constant companion of my waking hours, and the central and beloved figure of my dreams.</p>',
  45.     'post_status' => 'publish',
  46.     'post_type' => 'looplet',
  47. );
  48.  
  49. $add_posts_array = array($post1, $post2, $post3, $post4, $post5, $post6, $post7, $post8);
  50.  
  51. foreach ($add_posts_array as $post){
  52.     wp_insert_post( $post );
  53.  };
  54.  
  55. //And Now We Can import the images
  56. $siteaddress = get_site_url();
  57. $image_url = array ( $siteaddress . '/wp-content/plugins/looplet-plugin/arch.jpg', $siteaddress . '/wp-content/plugins/looplet-plugin/taxi.jpg', $siteaddress . '/wp-content/plugins/looplet-plugin/cat.jpg', $siteaddress . '/wp-content/plugins/looplet-plugin/dog.jpg' );
  58. foreach ( $image_url as $image_url ) {
  59. $upload_dir = wp_upload_dir();
  60. $image_data = file_get_contents($image_url);
  61. $filename = basename($image_url);
  62. if(wp_mkdir_p($upload_dir['path']))
  63.     $file = $upload_dir['path'] . '/' . $filename;
  64. else
  65.     $file = $upload_dir['basedir'] . '/' . $filename;
  66. file_put_contents($file, $image_data);
  67.  
  68. $wp_filetype = wp_check_filetype($filename, null );
  69. $attachment = array(
  70.     'post_mime_type' => $wp_filetype['type'],
  71.     'post_title' => sanitize_file_name($filename),
  72.     'post_content' => '',
  73.     'post_status' => 'inherit'
  74. );
  75. $attach_id = wp_insert_attachment( $attachment, $file, $post_id );
  76. require_once(ABSPATH . 'wp-admin/includes/image.php');
  77. $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
  78. wp_update_attachment_metadata( $attach_id, $attach_data );
  79. }
  80.  
  81.  
  82. //This is Where the trouble lies. How do I assign the various thumbnails I imported to the inserted posts as post //thumbnails?
  83. set_post_thumbnail( $post_id, $attach_id );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement