WordPress.org

Plugin Directory

Changeset 748353


Ignore:
Timestamp:
07/30/13 15:49:52 (4 years ago)
Author:
jmlapam
Message:

bugfix image sizes

Location:
jm-twitter-cards/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • jm-twitter-cards/trunk/jm-twitter-cards.php

    r745776 r748353  
    66Author: Julien Maury 
    77Author URI: http://tweetpress.fr 
    8 Version: 3.2.7 
     8Version: 3.2.8 
    99License: GPL2++ 
    1010*/ 
     
    5050} 
    5151 
    52 // get meta values 
    53  
    5452 
    5553// Add stuffs in init such as img size 
    5654add_action('init','jm_tc_initialize'); 
    5755function jm_tc_initialize() { 
    58     if ( function_exists( 'add_theme_support' ) )  
    59     add_theme_support( 'post-thumbnails' ); 
    60     //if ( function_exists( 'add_image_size' ) ) /* no use */ 
    61     add_image_size( 'jmtc-small-thumb', 280, 150 );  /* the minimum size possible for Twitter Cards */ 
    62     add_image_size( 'jmtc-max-web-thumb', 435, 375 );  /* maximum web size for photo cards */ 
    63     add_image_size( 'jmtc-max-mobile-non-retina-thumb', 280, 375 );  /* maximum non retina mobile size for photo cards  */ 
    64     add_image_size( 'jmtc-max-mobile-retina-thumb', 560, 750 );  /* maximum retina mobile size for photo cards  */ 
     56    if ( function_exists( 'add_theme_support' ) ) add_theme_support( 'post-thumbnails' ); 
     57    add_image_size( 'jmtc-small-thumb', 280, 150, true );  /* the minimum size possible for Twitter Cards */ 
     58    add_image_size( 'jmtc-max-web-thumb', 435, 375, true );  /* maximum web size for photo cards */ 
     59    add_image_size( 'jmtc-max-mobile-non-retina-thumb', 280, 375, true );  /* maximum non retina mobile size for photo cards  */ 
     60    add_image_size( 'jmtc-max-mobile-retina-thumb', 560, 750, true );  /* maximum retina mobile size for photo cards  */ 
    6561} 
    6662 
     
    6965function jm_tc_thumbnail_sizes() { 
    7066    $opts = jm_tc_get_options();  
    71     if( $thumbnail_size = get_post_meta( get_the_ID(), 'cardImgSize', true ))  $size = $thumbnail_size; else $size = $opts ['twitterCardImgSize']; 
     67    global $post; 
     68    if( '' != ( $thumbnail_size = get_post_meta( $post->ID, 'cardImgSize', true ) ) ) $size = $thumbnail_size; else $size = $opts ['twitterCardImgSize']; 
    7269    switch ($size) { 
    7370    case 'small': 
    74         $twitterCardImgSize = array(280,150); 
     71        $twitterCardImgSize = 'jmtc-small-thumb'; 
    7572         
    7673        break; 
    7774    case 'web': 
    78         $twitterCardImgSize = array(435,375); 
     75        $twitterCardImgSize = 'jmtc-max-web-thumb'; 
    7976         
    8077        break; 
    8178    case 'mobile-non-retina': 
    82         $twitterCardImgSize = array(280,375); 
     79        $twitterCardImgSize = 'jmtc-max-mobile-non-retina-thumb'; 
    8380         
    8481        break; 
    8582    case 'mobile-retina': 
    86         $twitterCardImgSize = array(560,750); 
     83        $twitterCardImgSize = 'jmtc-max-mobile-retina-thumb'; 
     84         
    8785        break; 
    8886    default:  
    89         $twitterCardImgSize = array(280,150); 
     87        $twitterCardImgSize = 'jmtc-small-thumb'; 
    9088        ?><!-- @(-_-)] --><?php 
    9189        break; 
     
    149147        <p> 
    150148        <label for="twitterCardImage"><?php _e('Set another source as twitter image (enter URL)', 'jm-tc'); ?> :</label><br /> 
    151         <input id="twitterCardImage" type="url" name="cardImage" style="padding:.3em;" size="120" class="regular-text" value="<?php echo get_post_meta(get_the_ID(),'cardImage',true); ?>" /> 
     149        <input id="twitterCardImage" type="url" name="cardImage" style="padding:.3em;" size="120" class="regular-text" value="<?php echo get_post_meta($post->ID,'cardImage',true); ?>" /> 
    152150        </p> 
    153151        <p class="description"><?php _e('(This is optional but some users wanted alternatives for featured image.)', 'jm-tc'); ?></p> 
     
    177175            <section style="background-color:#eee; margin:1em; padding:1em;line-height:150%;"> 
    178176            <p><label for="twitterImageWidth"><?php _e('Image width', 'jm-tc'); ?> :</label> 
    179             <input id="twitterImageWidth" type="number" min="280" name="cardPhotoWidth" class="small-number" value="<?php echo get_post_meta(get_the_ID(),'cardPhotoWidth',true); ?>" /> 
     177            <input id="twitterImageWidth" type="number" min="280" name="cardPhotoWidth" class="small-number" value="<?php echo get_post_meta($post->ID,'cardPhotoWidth',true); ?>" /> 
    180178            </p> 
    181179            <p> 
    182180            <label for="twitterImageHeight"><?php _e('Image height', 'jm-tc'); ?> :</label> 
    183             <input id="twitterImageHeight" type="number" min="150" name="cardPhotoHeight" class="small-number" value="<?php echo get_post_meta(get_the_ID(),'cardPhotoHeight',true); ?>" /> 
     181            <input id="twitterImageHeight" type="number" min="150" name="cardPhotoHeight" class="small-number" value="<?php echo get_post_meta($post->ID,'cardPhotoHeight',true); ?>" /> 
    184182            </p> 
    185183            </section> 
     
    190188            <p> 
    191189            <label for="cardData1"><?php _e('Enter the first key data for product', 'jm-tc'); ?> :</label> 
    192             <input id="cardData1" type="text" name="cardData1" style="padding:.3em;" class="regular-text" value="<?php echo get_post_meta(get_the_ID(),'cardData1',true); ?>" /> 
     190            <input id="cardData1" type="text" name="cardData1" style="padding:.3em;" class="regular-text" value="<?php echo get_post_meta($post->ID,'cardData1',true); ?>" /> 
    193191            </p> 
    194192            <p> 
    195193            <label for="cardLabel1"><?php _e('Enter the first key label for product', 'jm-tc'); ?> :</label> 
    196             <input id="cardLabel1" type="text" name="cardLabel1" style="padding:.3em;" class="regular-text" value="<?php echo get_post_meta(get_the_ID(),'cardLabel1',true); ?>" /> 
     194            <input id="cardLabel1" type="text" name="cardLabel1" style="padding:.3em;" class="regular-text" value="<?php echo get_post_meta($post->ID,'cardLabel1',true); ?>" /> 
    197195            </p> 
    198196            <p> 
    199197            <label for="cardData2"><?php _e('Enter the second key data for product', 'jm-tc'); ?> :</label> 
    200             <input id="cardData2" type="text" name="cardData2" style="padding:.3em;" class="regular-text" value="<?php echo get_post_meta(get_the_ID(),'cardData2',true); ?>" /> 
     198            <input id="cardData2" type="text" name="cardData2" style="padding:.3em;" class="regular-text" value="<?php echo get_post_meta($post->ID,'cardData2',true); ?>" /> 
    201199            </p> 
    202200            <p> 
    203201            <label for="cardLabel2"><?php _e('Enter the second key label for product', 'jm-tc'); ?> :</label> 
    204             <input id="cardLabel2" type="text" name="cardLabel2" style="padding:.3em;" class="regular-text" value="<?php echo get_post_meta(get_the_ID(),'cardLabel2',true); ?>" /> 
     202            <input id="cardLabel2" type="text" name="cardLabel2" style="padding:.3em;" class="regular-text" value="<?php echo get_post_meta($post->ID,'cardLabel2',true); ?>" /> 
    205203            </p> 
    206204            <p class="description"><?php _e('Here you can set 2 key details for your product (e.g price, size, etc)', 'jm-tc'); ?></p> 
     
    370368                if($opts['twitterCardSEOTitle'] == 'yes' && get_post_meta(get_the_ID(), '_aioseop_title', true) ) { $cardTitle  = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_title', true))); } else { $cardTitle = the_title_attribute( array('echo' => false) );} 
    371369                if($opts['twitterCardSEODesc'] == 'yes' && get_post_meta(get_the_ID(), '_aioseop_description', true)) { $cardDescription = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_description', true))); } else { $cardDescription = get_excerpt_by_id($post->ID); } 
    372             } elseif ( $cardTitleKey != '' && $cardDescKey != '' ) {  
     370            } elseif ( $tctitle && $tcdesc && $cardTitleKey != '' && $cardDescKey != '' ) {  
    373371                // avoid array to string notice on title and desc 
    374372                $cardTitle = $tctitle; 
     
    398396            echo '<meta name="twitter:description" content="' . $cardDescription . '">'."\n";  
    399397 
    400             if( get_the_post_thumbnail( $post->ID ) && empty($cardImage) && empty($cardImgSize) && function_exists('jm_tc_thumbnail_sizes') ) { //featured image is set but not cardImage 
    401                 $thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), jm_tc_thumbnail_sizes()); 
    402                 echo '<meta name="twitter:image" content="' . $thumb[0] . '">'."\n"; 
    403             } elseif( !empty($cardImage) ) { // cardImage is set 
    404                 echo '<meta name="twitter:image" content="' . $cardImage . '">'."\n"; 
    405             } elseif ( empty($cardImage) && !empty($cardImgSize) && function_exists('jm_tc_thumbnail_sizes') ){ 
    406                 $thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ),jm_tc_thumbnail_sizes()); 
    407                 echo '<meta name="twitter:image" content="' . $thumb[0] . '">'."\n"; 
     398            if( has_post_thumbnail() ) { 
     399                  if(  $cardImage != '' ) { // cardImage is set 
     400                    echo '<meta name="twitter:image" content="' . $cardImage . '">'."\n"; 
     401                } else { 
     402                    $image_attributes = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), jm_tc_thumbnail_sizes() ); 
     403                    echo '<meta name="twitter:image" content="' . $image_attributes[0] . '">'."\n"; 
     404                }  
    408405            } else { //fallback 
    409406                echo '<meta name="twitter:image" content="' . $opts['twitterImage'] . '">'."\n"; 
    410407            } 
     408             
    411409            if($cardType  == 'photo') { 
    412410                if(!empty($cardPhotoWidth) && !empty($cardPhotoHeight)) { 
  • jm-twitter-cards/trunk/readme.txt

    r745776 r748353  
    115115== Changelog == 
    116116 
     117=  3.2.8 = 
     118* 30 Jul 2013 
     119* bugfix with image size. 
     120* add crop to thumbnails to prevent error due to images with sumarry large image cards 
     121 
    117122=  3.2.7 = 
    118123* 24 Jul 2013 
Note: See TracChangeset for help on using the changeset viewer.