Exemplo n.º 1
0
 /**
  * Add new comment to WP post
  *
  * @param int $postId
  * @param array $comment
  * @return bool|int created comment id or false on failure
  */
 public static function addPostComment($postId, $comment)
 {
     $filter = array('meta_key' => 'external_id', 'meta_value' => $comment['id']);
     \Plugin\Service::pingDB();
     if (get_comments($filter)) {
         $result = false;
     } else {
         $wpComment = array('comment_post_ID' => $postId, 'comment_author' => $comment['from']['name'], 'comment_author_url' => 'http://facebook.com/' . $comment['from']['id'], 'comment_date' => date('Y-m-d H:i:s', strtotime($comment['created_time'])), 'comment_content' => wp_strip_all_tags($comment['message']), 'comment_approved' => 1);
         $commentId = wp_insert_comment($wpComment);
         if ($commentId) {
             add_comment_meta($commentId, 'external_id', $comment['id']);
         }
         $result = $commentId;
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Download image from URL and link it as post thumbnail
  *
  * @param array $image must constist postId and image
  */
 public function crawlImage($data)
 {
     require_once ABSPATH . 'wp-admin/includes/file.php';
     require_once ABSPATH . 'wp-admin/includes/media.php';
     require_once ABSPATH . 'wp-admin/includes/image.php';
     $file = array('name' => uniqid() . '.jpg', 'tmp_name' => download_url($data['image']));
     \Plugin\Service::pingDB();
     if (!is_wp_error($file['tmp_name'])) {
         $attachmentId = media_handle_sideload($file, $data['postId']);
     }
     if (isset($attachmentId)) {
         set_post_thumbnail($data['postId'], $attachmentId);
     }
     if (file_exists($file['tmp_name'])) {
         unlink($file['tmp_name']);
     }
     echo 'Crawled image for post ', $data['postId'], "\n";
 }
 public function createImporter()
 {
     $plugin = \Plugin\Service::init(require 'config/test.config.php');
     return new Service($plugin);
 }