ID))
return $url;
if ( $this->uses_amazon_featured( $post->ID ) === false )
return $url;
$url = $this->amazon_featured_get_thumbnail_src( $post->ID );
return $url;
}
function get_attachment_image_src( $image, $attachment_id, $size, $icon ){
global $post;
$id = $post->ID;
if( $id == 0 )
return $image;
if ( $this->uses_amazon_featured( $id ) === false )
return $image;
$image_url = $this->amazon_featured_get_thumbnail_src( $id );
$image = array( $image_url, 0, 0 );
return $image;
}
function amazon_featured_add_url_metabox() {
$excluded_post_types = array('attachment', 'revision', 'nav_menu_item', 'wpcf7_contact_form',);
foreach ( get_post_types( '', 'names' ) as $post_type ) {
if ( in_array( $post_type, $excluded_post_types ) )
continue;
add_meta_box('amazon_featured_url_metabox','Amazon Featured Image',array( $this, 'amazon_featured_url_metabox'),$post_type,'side','default');
}
}
function amazon_featured_url_metabox( $post ) {
$amazon_featured_url = get_post_meta( $post->ID, $this->_amazon_featured_url(), true );
$amazon_featured_alt = get_post_meta( $post->ID, '_amazon_featured_alt', true );
$has_img = strlen( $amazon_featured_url ) > 0;
$show_if_img = '';
$hide_if_img = '';
if ( $has_img )
$hide_if_img = 'display:none;';
else
$show_if_img = 'display:none;';
?>
_amazon_featured_url(), $url );
}
if ( isset( $_POST['amazon_featured_alt'] ) )
update_post_meta( $post_ID, '_amazon_featured_alt', strip_tags( $_POST['amazon_featured_alt'] ) );
}
function _amazon_featured_url() {
return apply_filters( 'amazon_featured_post_meta_key', '_amazon_featured_url' );
}
function uses_amazon_featured( $id ) {
$image_url = $this->amazon_featured_get_thumbnail_src( $id );
if ( $image_url === false )
return false;
else
return true;
}
function attachment_image_attributes ($attr = array(), $attachment = array(), $size = false ){
global $post;
$id = $post->ID;
if( $id == 0 )
return $attr;
if ( $this->uses_amazon_featured( $id ) === false )
return $attr;
unset($attr['srcset'],$attr['sizes']);
$image_url = $this->amazon_featured_get_thumbnail_src( $id );
$alt = get_post_meta( $id, '_amazon_featured_alt', true );
$alt = $alt == '' && isset( $attr['alt'] ) ? $attr['alt'] : $alt ;
$attr['src'] = $image_url;
$attr['class'] = $attr['class'].' amazon-featured-image';
$attr['alt'] = $alt;
$attr['style'] = 'width: auto;';
return $attr;
}
function amazon_featured_get_thumbnail_src( $id, $called_on_save = false ) {
if(is_admin())
return false;
$this->unfilter_override_thumbnail_id();
$regular_feat_image = get_post_meta( $id, '_thumbnail_id', true );
$this->filter_override_thumbnail_id();
if ( isset( $regular_feat_image ) && $regular_feat_image > 0 )
return false;
$image_url = get_post_meta( $id, $this->_amazon_featured_url(), true );
if($image_url != '')
return $image_url;
return false;
}
function override_thumbnail_check( $null, $object_id, $meta_key ) {
$result = null;
if ( '_thumbnail_id' === $meta_key ) {
if ( $this->uses_amazon_featured( $object_id ) ){
$tempid = get_option('amazon_product_dummy_featured_image_ID', '-1' );
//need to get an attachment ID that is valid to fake it out.
if( $tempid == '-1' || !get_post_status($tempid) ){
$rndid = -1;
$postschk = new WP_Query( array('post_type' => 'attachment', 'posts_per_page' => 1, 'post_status' => 'inherit' ) );
if(is_object($postschk) && !empty($postschk->posts)){
$rndid = $postschk->posts[0]->ID;
update_option('amazon_product_dummy_featured_image_ID', $rndid );
}
$result = $rndid ;
}else{
$result = $tempid;
}
}
}
return $result;
}
function filter_override_thumbnail_id() {
foreach ( get_post_types() as $post_type ) {
add_filter( "get_${post_type}_metadata", array( $this, 'override_thumbnail_check'), 10, 3 );
}
}
function unfilter_override_thumbnail_id() {
foreach ( get_post_types() as $post_type ) {
remove_filter( "get_${post_type}_metadata", array( $this, 'override_thumbnail_check'), 10 );
}
}
}
if( (bool) get_option('apipp_product_featured_image', false) === true){
new newExtFeatImgInc();
}