/**
  * Attachments are created slightly differently (especially for images)
  *
  * @return boolean success
  */
 protected function insert_post()
 {
     if ($this->doc->getProfileAlias() == 'image') {
         $enclosure = SdkWrapper::getImageEnclosure($this->doc);
         $id_or_error = pmp_media_sideload_image($enclosure->href, $this->parent_syncer->post->ID);
     } else {
         $data = array('post_title' => "draft pmp-pulled content: {$this->doc->attributes->guid}", 'post_content' => "draft pmp-pulled content: {$this->doc->attributes->guid}", 'post_author' => get_current_user_id(), 'post_type' => 'pmp_attachment', 'post_status' => 'inherit', 'post_parent' => $this->parent_syncer->post->ID);
         $id_or_error = wp_insert_post($data, true);
     }
     // handle errors
     if (is_wp_error($id_or_error)) {
         var_log("insert_post ERROR for attachment [{$this->doc->attributes->guid}] - {$id_or_error->get_error_message()}");
         return false;
     } else {
         $this->post = get_post($id_or_error);
         $this->pmp_debug("   ** created new attachment");
         return true;
     }
 }
Ejemplo n.º 2
0
 function test_pmp_enclosures_for_media()
 {
     $new_post = $this->factory->post->create();
     $url = 'http://publicmediaplatform.org/wp-content/uploads/logo1.png';
     $desc = 'Test description';
     $image_id = pmp_media_sideload_image($url, $new_post, $desc);
     $enclosures = pmp_enclosures_for_media($image_id);
     $this->assertTrue((bool) count($enclosures));
     $first_enc = $enclosures[0];
     // These should be present at the first level of the returned array
     $expected_keys_first = array('href', 'meta', 'type');
     foreach ($expected_keys_first as $expected_key) {
         $this->assertTrue(in_array($expected_key, array_keys((array) $first_enc)));
     }
     // The meta array should have these keys, indicating the crop and size of the image
     $expected_keys_second = array('crop', 'width', 'height');
     foreach ($expected_keys_second as $expected_key) {
         $this->assertTrue(in_array($expected_key, array_keys((array) $first_enc->meta)));
     }
     // Make sure the 'crop' value is set using PMP best practices
     // See: https://support.pmp.io/docs#best-practices-image-crops
     $pmp_image_crops = array('primary', 'large', 'medium', 'small', 'square');
     foreach ($enclosures as $enc) {
         $this->assertTrue(in_array($enc->meta->crop, $pmp_image_crops));
     }
 }