/** * Create blog post from tweet * * @param array $args * @return bool */ function create_blog_post($args = array()) { extract($args); // Add a space if we have a prefix $title_prefix = empty($title_prefix) ? '' : trim($title_prefix) . ' '; $post_content = $this->link_entities(false); // Append image to post if there is one, can't set it as a featured image until after save if (!empty($this->featured_image_id)) { $size = apply_filters('aktt_featured_image_size', 'medium'); $post_content .= "\n\n" . wp_get_attachment_image($this->featured_image_id, $size); } $gmt_time = self::twdate_to_time($this->date()); // Build the post data $data = array('post_title' => $title_prefix . $this->title(), 'post_content' => $post_content, 'post_author' => $post_author, 'post_status' => $post_status, 'post_type' => 'post', 'post_date' => date('Y-m-d H:i:s', AKTT::gmt_to_wp_time($gmt_time)), 'post_date_gmt' => date('Y-m-d H:i:s', $gmt_time), 'guid' => $this->guid() . '-post'); $data = apply_filters('aktt_tweet_create_blog_post_data', $data); // hook in here if you want to conditionally skip blog post creation if (!apply_filters('aktt_tweet_create_blog_post', true, $data, $this)) { return false; } $this->blog_post_id = wp_insert_post($data, true); if (is_wp_error($this->blog_post_id)) { AKTT::log('WP_Error:: ' . $this->blog_post_id->get_error_message()); return false; } // have to set up taxonomies after the insert in case we are in a context without // a 'current user' - see: http://core.trac.wordpress.org/ticket/19373 wp_set_object_terms($this->blog_post_id, intval($post_category), 'category'); wp_set_object_terms($this->blog_post_id, array_map('trim', explode(',', $post_tags)), 'post_tag'); // hook in here and return false to not set the format to "status", // or return another format to use that format instead of status if ($post_format = apply_filters('aktt_tweet_create_blog_post_format', 'status', $data, $this)) { set_post_format($this->blog_post_id, $post_format); } if (!empty($this->featured_image_id)) { update_post_meta($this->blog_post_id, '_thumbnail_id', $this->featured_image_id); } update_post_meta($this->blog_post_id, '_aktt_tweet_id', $this->id()); // twitter's tweet ID update_post_meta($this->blog_post_id, '_aktt_tweet_post_id', $this->post_id); // twitter's post ID // Add it to the tweet's post_meta as well update_post_meta($this->post_id, '_aktt_tweet_blog_post_id', $this->blog_post_id); // Let Social know to aggregate info about this post $account = false; foreach (AKTT::$accounts as $aktt_account) { if ($aktt_account->social_acct->id() == $this->data->user->id_str) { $account = $aktt_account->social_acct; break; } } if ($account) { Social::instance()->add_broadcasted_id($this->blog_post_id, 'twitter', $this->id(), $this->content(), $account, null); } // Let the account know we were successful return true; }