Skip to content

Instantly share code, notes, and snippets.

@landbryo
Last active May 2, 2022 17:56
Show Gist options
  • Save landbryo/f8cc3bfd0710f35e623307f21fc8bfab to your computer and use it in GitHub Desktop.
Save landbryo/f8cc3bfd0710f35e623307f21fc8bfab to your computer and use it in GitHub Desktop.
Fix picker image meta for MG
/**
* After attachment has been created, make sure to
* label it as an external image source so the URL can be re-written.
*/
add_filter( 'capi_image_attachment_meta', function( $metadata, $attachment_id ) {
// Mark as external image source.
update_post_meta( $attachment_id, '_external_image_source', 1 );
return $metadata;
}, 10, 2 );
/**
* Set both `url` and `file` bits to original resource URL instead of WP asset.
*/
add_filter( 'capi_image_upload_bits', function( $upload, $post_id, $url ) {
$upload['url'] = $url;
$upload['file'] = $url;
return $upload;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment