MediaPress media files are just a sugarcoated version of WordPress attachment. There are differences in the image sizes and some properties and file storage locations.
With MediaPress 1.3.6 and above, we have an API to import the WordPress attachment to a MediaPress Gallery.
mpp_import_attachment( $attachment_id, $gallery_id, $overrides = array() )
- $attachment_id(required)(integer):- Valid WordPress attachment id.
- $gallery_id(required)(integer):- a valid MediaPress gallery id
- $overrides(optional)(array):- Override any extra property of the media.
media id on success or WP_Error object on failure.
That will import WordPress attachment id 215 to our gallery if there is no error.
What Happens Internally:-
- We test for the validity of attachment
- We test for the validity of gallery
- If both are valid, we test if the media specified by the attachment is a valid type of media for MediaPress(e.g allowed file type)
- If all is well, we check that the gallery type can contain media of the given type.
- If we reach here, we copy the attached file(original file) from the attachment to the MediaPress’s gallery directory. Delete the various image sizes of the attchment(including the original)
- We regenerate the attachment meta data again(It will regenerate image sizes if the memdia type is photo)
- If everything goes well, return the media id which is same as the attachment id.
- If any of the above steps go wrong, we return an instance of WP_Error detailing the problem.