Skip to content

Commit

Permalink
Injeção de thumbnail id para chamadas hardcode
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-brito committed Apr 6, 2017
1 parent cbb1cf3 commit 63ece4e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions rb-external-thumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,26 @@ function rb_has_post_thumbnail($metadata, $object_id, $meta_key, $single){
}
return $metadata;
}

add_filter( 'get_post_metadata', 'rb_external_inject_thumbnail_id', 10, 4 );

function rb_external_inject_thumbnail_id ( $value, $post_id, $meta_key, $single ) {
if ( $meta_key === '_thumbnail_id' ) {
$url_thumbnail_external = get_post_meta( $post_id ,'thumbnail_external', true );
if( !empty($url_thumbnail_external) ){
return "ext-" . $post_id;
}
}
return $value;
}

add_filter( 'wp_get_attachment_image_src', 'rb_external_attachment_image_src', 10, 4 );

function rb_external_attachment_image_src( $image, $attachment_id, $size, $icon ){
if(isset($attachment_id) && !empty($attachment_id) && substr($attachment_id, 0, 3) === "ext"){
$id = substr($attachment_id, 4);
$thumbnail = get_post_meta( $id ,'thumbnail_external', true );
return Array ( $thumbnail, 0, 0, false );
}
return $image;
}

0 comments on commit 63ece4e

Please sign in to comment.