returnFeed(); foreach ($newsFeed as $article) { //foreach ($article->categories as $cats) // error_log($cats); $opts = array('post_status' => 'publish', 'post_type' => 'post'); $allPosts = get_posts($opts); $post = array( 'post_author' => 3, 'post_category' => array(3,4), 'post_content' => $article->content, 'post_status' => 'publish', 'post_title' => $article->heading, ); global $wpdb; global $wpdb; $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_name = %s', sanitize_title_with_dashes($article->heading)); $cID = $wpdb->get_var( $query ); if ( empty($cID) ) { // do nothing } else { $newId = wp_insert_post($post, $wp_error); } // insert featured image if( !class_exists( 'WP_Http' ) ) include_once( ABSPATH . WPINC. '/class-http.php' ); $photo = new WP_Http(); $photo = $photo->request( $article->largeURL ); $attachment = wp_upload_bits( $photo_name . '.jpg', null, $photo['body'], date("Y-m", strtotime( $photo['headers']['last-modified'] ) ) ); $filetype = wp_check_filetype( basename( $attachment['file'] ), null ); $postinfo = array( 'post_mime_type' => $filetype['type'], 'post_title' => $article->heading . ' ', 'post_content' => '', 'post_status' => 'inherit', ); $filename = $attachment['file']; $attach_id = wp_insert_attachment( $postinfo, $filename, $newId ); if( !function_exists( 'wp_generate_attachment_data' ) ) require_once(ABSPATH . "wp-admin" . '/includes/image.php'); $attach_data = wp_generate_attachment_metadata( $attach_id, $filename ); wp_update_attachment_metadata( $attach_id, $attach_data ); error_log(set_post_thumbnail($newId,$attach_id)); } //$body = 'this is an email from newsreach'; } function run_on_activate() { // for notifications if( !wp_next_scheduled( 'content_scheduler_notify' ) ) { wp_schedule_event( time(), 'myMinute', 'content_scheduler_notify' ); } } // end run_on_activate() function add_cs_cron_fn( $array ) { // set our 6 hours, units in seconds $period = 60; // use that for 'interval' below. // 'quarterday' is a unique name for our custom period $array['myMinute'] = array( 'interval' => $period, 'display' => 'Every 1 minute' ); return $array; } // end add_cs_cron_fn() function run_on_deactivate() { // for notifications wp_clear_scheduled_hook('content_scheduler_notify'); } // end run_on_activate() } /** * @global * Start up **/ $newsInt = new newsReach(); ?> /* EOF */ id = $postId; $this->heading = $heading; $this->content = $content; $this->largeURL = $largeURL; $this->smallURL = $smallURL; $this->categories = $categories; } } class newsReachAPI { function getFeed($xmlUrl) { $xml = simplexml_load_file($xmlUrl); $articles = array(); foreach ($xml->Article as $item) { $catList = array(); foreach ($item->Categories->children() as $child) array_push($catList,$this->categoryMatching($child)); $newArticle = new article($item->Heading,$item->Contents,$item->Picture->Large->URL,$item->Picture->Small->URL,$catList); array_push($articles,$newArticle); } return $articles; } function categoryMatching($categoryIn) { $allCategories = get_categories(); foreach ($allCategories as $currentCategory) { if ($currentCategory->name == $categoryIn) { return $currentCategory->term_id; } } return $categoryIn; } public function returnFeed() { $articlesIn = $this->getFeed('http://feeds.directnews.co.uk/?e4f740aa-c1f2-43cd-9ce1-09a65379142e'); return $articlesIn; } } ?>