WordPress.org

Plugin Directory

Changeset 780141


Ignore:
Timestamp:
09/30/13 05:11:50 (7 months ago)
Author:
greenshady
Message:

Update to version 0.9.0.

Location:
get-the-image
Files:
12 added
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • get-the-image/trunk/get-the-image.php

    r641468 r780141  
    33 * Plugin Name: Get The Image 
    44 * Plugin URI: http://themehybrid.com/plugins/get-the-image 
    5  * Description: This is a highly intuitive script that can grab an image by custom field input, post attachment, or extracting it from the post's content. 
    6  * Version: 0.8.1 
     5 * Description: This is a highly intuitive script that can grab an image by custom field, featured image, post attachment, or extracting it from the post's content. 
     6 * Version: 0.9.0 
    77 * Author: Justin Tadlock 
    88 * Author URI: http://justintadlock.com 
    9  * 
     9 */ 
     10 
     11/** 
    1012 * Get the Image - An advanced post image script for WordPress. 
    1113 * 
     
    2426 * 
    2527 * @package   GetTheImage 
    26  * @version   0.8.1 
     28 * @version   0.9.0 
    2729 * @author    Justin Tadlock <justin@justintadlock.com> 
    28  * @copyright Copyright (c) 2008 - 2012, Justin Tadlock 
     30 * @copyright Copyright (c) 2008 - 2013, Justin Tadlock 
    2931 * @link      http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin 
    3032 * @license   http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
     
    5557 */ 
    5658function get_the_image( $args = array() ) { 
     59    global $_wp_additional_image_sizes; 
    5760 
    5861    /* Set the default arguments. */ 
    5962    $defaults = array( 
     63 
     64        /* Post the image is associated with. */ 
     65        'post_id'            => get_the_ID(), 
     66 
     67        /* Methods of getting an image (in order). */ 
    6068        'meta_key'           => array( 'Thumbnail', 'thumbnail' ), // array|string 
    61         'post_id'            => get_the_ID(), 
     69        'the_post_thumbnail' => true, 
    6270        'attachment'         => true, 
    63         'the_post_thumbnail' => true, // WP 2.9+ image function 
    64         'size'               => 'thumbnail', 
     71        'image_scan'         => false, 
     72        'callback'           => null, 
    6573        'default_image'      => false, 
     74 
     75        /* Attachment-specific arguments. */ 
     76        'size'               => isset( $_wp_additional_image_sizes['post-thumbnail'] ) ? 'post-thumbnail' : 'thumbnail', 
    6677        'order_of_image'     => 1, 
     78 
     79        /* Format/display of image. */ 
    6780        'link_to_post'       => true, 
    6881        'image_class'        => false, 
    69         'image_scan'         => false, 
    7082        'width'              => false, 
    7183        'height'             => false, 
    72         'format'             => 'img', 
     84        'before'             => '', 
     85        'after'              => '', 
     86 
     87        /* Captions. */ 
     88        'caption'            => false, // Default WP [caption] requires a width. 
     89 
     90        /* Saving the image. */ 
    7391        'meta_key_save'      => false, 
    7492        'thumbnail_id_save'  => false, // Set 'featured image'. 
    75         'callback'           => null, 
    7693        'cache'              => true, 
    77         'before'             => '', 
    78         'after'              => '', 
     94 
     95        /* Return/echo image. */ 
     96        'format'             => 'img', 
    7997        'echo'               => true, 
     98 
     99        /* Deprecated arguments. */ 
    80100        'custom_key'         => null, // @deprecated 0.6. Use 'meta_key'. 
    81101        'default_size'       => null, // @deprecated 0.5.  Use 'size'. 
     
    87107    /* Merge the input arguments and the defaults. */ 
    88108    $args = wp_parse_args( $args, $defaults ); 
     109 
     110    /* If no post ID, return. */ 
     111    if ( empty( $args['post_id'] ) ) 
     112        return false; 
    89113 
    90114    /* If $default_size is given, overwrite $size. */ 
     
    173197 
    174198        /* Get the image attributes. */ 
    175         $atts = wp_kses_hair( $image_html, array( 'http' ) ); 
     199        $atts = wp_kses_hair( $image_html, array( 'http', 'https' ) ); 
    176200 
    177201        /* Loop through the image attributes and add them in key/value pairs for the return array. */ 
     
    179203            $out[ $att['name'] ] = $att['value']; 
    180204 
    181         $out['url'] = $out['src']; // @deprecated 0.5 Use 'src' instead of 'url'. 
     205        if ( !empty( $out['src'] ) ) 
     206            $out['url'] = $out['src']; // @deprecated 0.5 Use 'src' instead of 'url'. 
    182207 
    183208        /* Return the array of attributes. */ 
     
    262287    $image = wp_get_attachment_image_src( $post_thumbnail_id, $size ); 
    263288 
    264     /* Get the attachment excerpt to use as alt text. */ 
    265     $alt = trim( strip_tags( get_post_field( 'post_excerpt', $post_thumbnail_id ) ) ); 
     289    /* Get the attachment alt text. */ 
     290    $alt = trim( strip_tags( get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true ) ) ); 
     291 
     292    /* Get the attachment caption. */ 
     293    $caption = get_post_field( 'post_excerpt', $post_thumbnail_id ); 
    266294 
    267295    /* Return both the image URL and the post thumbnail ID. */ 
    268     return array( 'src' => $image[0], 'post_thumbnail_id' => $post_thumbnail_id, 'alt' => $alt ); 
     296    return array( 'src' => $image[0], 'post_thumbnail_id' => $post_thumbnail_id, 'alt' => $alt, 'caption' => $caption ); 
    269297} 
    270298 
     
    329357        $image = wp_get_attachment_image_src( $attachment_id, $args['size'] ); 
    330358 
    331         /* Get the attachment excerpt. */ 
    332         $alt = trim( strip_tags( get_post_field( 'post_excerpt', $attachment_id ) ) ); 
     359        /* Get the attachment alt text. */ 
     360        $alt = trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ); 
     361 
     362        /* Get the attachment caption. */ 
     363        $caption = get_post_field( 'post_excerpt', $attachment_id ); 
    333364 
    334365        /* Save the attachment as the 'featured image'. */ 
     
    337368 
    338369        /* Return the image URL. */ 
    339         return array( 'src' => $image[0], 'alt' => $alt ); 
     370        return array( 'src' => $image[0], 'alt' => $alt, 'caption' => $caption ); 
    340371    } 
    341372 
     
    398429 
    399430    /* If there is alt text, set it.  Otherwise, default to the post title. */ 
    400     $image_alt = ( ( !empty( $image['alt'] ) ) ? $image['alt'] : apply_filters( 'the_title', get_post_field( 'post_title', $post_id ) ) ); 
     431    $image_alt = ( ( !empty( $image['alt'] ) ) ? $image['alt'] : get_post_field( 'post_title', $post_id ) ); 
    401432 
    402433    /* If there is a width or height, set them as HMTL-ready attributes. */ 
     
    407438    if ( is_array( $meta_key ) ) { 
    408439        foreach ( $meta_key as $key ) 
    409             $classes[] = sanitize_html_class( $key ); 
    410     } 
    411  
    412     /* Add the $size and any user-added $image_class to the class. */ 
    413     $classes[] = sanitize_html_class( $size ); 
    414     $classes[] = sanitize_html_class( $image_class ); 
     440            $classes[] = $key; 
     441    } 
     442 
     443    /* Add the $size to the class. */ 
     444    $classes[] = $size; 
     445 
     446    /* Get the custom image class. */ 
     447    if ( !empty( $image_class ) ) { 
     448        if ( !is_array( $image_class ) ) 
     449            $image_class = preg_split( '#\s+#', $image_class ); 
     450        $classes = array_merge( $classes, $image_class ); 
     451    } 
     452 
     453    /* Sanitize all the classes. */ 
     454    $classes = array_map( 'sanitize_html_class', $classes ); 
    415455 
    416456    /* Join all the classes into a single string and make sure there are no duplicates. */ 
     
    422462    /* If $link_to_post is set to true, link the image to its post. */ 
    423463    if ( $link_to_post ) 
    424         $html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( apply_filters( 'the_title', get_post_field( 'post_title', $post_id ) ) ) . '">' . $html . '</a>'; 
     464        $html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html . '</a>'; 
    425465 
    426466    /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */ 
     
    428468        $html = apply_filters( 'post_thumbnail_html', $html, $post_id, $image['post_thumbnail_id'], $size, '' ); 
    429469 
     470    /* If we're showing a caption. */ 
     471    if ( true === $args['caption'] && !empty( $image['caption'] ) ) 
     472        $html = img_caption_shortcode( array( 'caption' => $image['caption'], 'width' => $args['width'] ), $html ); 
     473 
    430474    return $html; 
    431475} 
  • get-the-image/trunk/readme.txt

    r641468 r780141  
    11=== Get the Image === 
     2 
    23Contributors: greenshady 
    34Donate link: http://themehybrid.com/donate 
    45Tags: image, images, thumbnail 
    5 Requires at least: 3.2 
    6 Tested up to: 3.5 
    7 Stable tag: 0.8.1 
     6Requires at least: 3.5 
     7Tested up to: 3.7 
     8Stable tag: 0.9.0 
     9License: GPLv2 or later 
     10License URI: http://www.gnu.org/licenses/gpl-2.0.html 
    811 
    9 An easy-to-use image script for adding things such as thumbnails and feature images. 
     12An easy-to-use image script for adding things such as thumbnail, slider, gallery, and feature images. 
    1013 
    1114== Description == 
    1215 
    13 *Get the Image* is a plugin that grabs images for you.  It was designed to make the process of things such as adding thumbnails, feature images, and/or other images to your blog much easier, but it's so much more than that.  It is an image-based representation of your WordPress posts. 
     16Get the Image is one of the most advanced thumbnail/image scripts ever created for WordPress.  
    1417 
    15 This is a highly intuitive script that can grab an image by custom field input, WP's post image feature, post attachment, or extracting it from the post's content. 
     18It is used everywhere from small blogs to large, enterprise-level solutions like [WordPress.com VIP](http://vip.wordpress.com/).  Get the Image offers something for everybody. Much of the reason for its success is because it uses standard WordPress code and methods for doing what it needs to do, which is to simply grab images. 
    1619 
    17 Support for this plugin is handled on the Theme Hybrid <a href="http://themehybrid.com/support">support forums</a>. 
     20The plugin was designed to make the process of adding thumbnail, featured, slider, gallery, and other images to your blog much easier, but it's so much more than that.  It is an image-based representation of your WordPress posts. 
     21 
     22This is a highly intuitive script that can grab an image by custom field input, WordPress' featured image, post attachment, or extracting it from the post's content.  Plus, a lot more! 
     23 
     24### A little history ### 
     25 
     26The original plugin was in launched 2008, which means it has several years of solid testing and development behind it.  It was created at a time when WordPress had very little native media support.  At the time, it was mostly used as a "thumbnail" script for magazine-/news-style sites.  But, it has grown into a much more flexible script over the years. 
     27 
     28Even with WordPress' more recent advancements in image management, many users still continue using this plugin because it offers a more robust image script than core WordPress. 
     29 
     30The plugin has been downloaded 100,000s of times and is used on millions of sites as part of WordPress theme packages. 
     31 
     32Other image plugins have come and gone, but Get the Image has stood the test of time with several years of successful installs and happy users. 
     33 
     34### Professional support ### 
     35 
     36If you need professional plugin support from me, the plugin author, you can access the support forums at [Theme Hybrid](http://themehybrid.com/support), which is a professional WordPress help/support site where I handle support for all my plugins and themes for a community of 40,000+ users (and growing). 
    1837 
    1938== Installation == 
    2039 
    21401. Upload `get-the-image` to the `/wp-content/plugins/` directory. 
    22 1. Activate the plugin through the 'Plugins' menu in WordPress. 
    23 1. Add the appropriate code to your template files as outlined in the `readme.html` file. 
    24  
    25 More detailed instructions are included in the plugin's `readme.html` file.  It is important to read through that file to properly understand all of the options and how the plugin works. 
     412. Activate the plugin through the 'Plugins' menu in WordPress. 
     423. Add the appropriate code to your template files as outlined in the `readme.md` file. 
    2643 
    2744== Frequently Asked Questions == 
    2845 
    29 = Why was this plugin created? = 
     46### Why was this plugin created? ### 
    3047 
    31 Many magazine-type themes require a lot of work when inputting images to make them look good.  This plugin was developed to make that process much easier for the end user.  But, at the same time, it needed to be flexible enough to handle anything. 
     48It was originally created to work with magazine/news themes.  These types of themes typically required a lot of work when inputting images to make them look good.  This plugin was developed to make that process much easier for the end user.  But, at the same time, it needed to be flexible enough to handle anything. 
    3249 
    33 Other scripts are bloated and offer odd solutions.  This plugin uses the built-in methods of WordPress to create things such as feature images, thumbnails, galleries, or whatever. 
     50However, over the years, it has grown to be one of the most robust image scripts for WordPress. 
    3451 
    35 This plugin was created to be a lightweight solution to handle a very powerful need in the WordPress community. 
    36  
    37 = How does it pull images? = 
     52### How does it grab images? ### 
    3853 
    39541.  Looks for an image by custom field (one of your choosing). 
    40 1. If no image is added by custom field, check for an image using `the_post_thumbnail()` (WordPress featured image). 
    41 1. If no image is found, it grabs an image attached to your post. 
    42 1. If no image is attached, it can extract an image from your post content (off by default). 
    43 1. If no image is found at this point, it will default to an image you set (not set by default). 
     552. If no image is added by custom field, check for an image using `the_post_thumbnail()` (WordPress featured image). 
     563. If no image is found, it grabs an image attached to your post. 
     574. If no image is attached, it can extract an image from your post content (off by default). 
     585. If no image is found at this point, it will fall back to a default image (not set by default). 
    4459 
    45 = How do I add it to my theme? = 
     60### How do I add it to my theme? ### 
    4661 
    47 There are several methods, but in general, you would use this call: 
     62There are several methods, but in general, you would use this call within The Loop. 
    4863 
    49 ` 
    50 <?php if ( function_exists( 'get_the_image' ) ) get_the_image(); ?> 
    51 ` 
     64    <?php if ( function_exists( 'get_the_image' ) ) get_the_image(); ?> 
    5265 
    53 To see all methods and options, refer to the `readme.html` file included with the theme download. 
     66To see all methods and options, refer to the `readme.md` file included with the plugin download. 
    5467 
    5568== Screenshots == 
    5669 
    57 You can view this plugin in action on my <a href="http://justintadlock.com" title="Justin Tadlock's blog">personal blog</a> (note the thumbnails). 
     701. Slider plus thumbnails. 
     712. Portfolio images. 
     723. Gallery-style thumbnails. 
    5873 
    5974== Changelog == 
    6075 
    61 **Version 0.8.1** 
     76### Version 0.9.0 ### 
     77 
     78#### Enhancements: #### 
     79 
     80* Caption support. FTW! 
     81* Multiple image classes now allowed via the `image_class` argument. 
     82* Use current theme's `post-thumbnail` as default image size if set via `set_post_thumbnail_size()`. 
     83 
     84#### Bug fixes: #### 
     85 
     86* Use the WordPress-saved attachment alt text for the image. 
     87* Only add `$out['src']` if `$out['url']` is set when returning as an array. 
     88* Allow `https` when returning as an array. 
     89* Use the correct variable (`$attachment_id`) when getting an image via attachment.  
     90 
     91### Version 0.8.1 ### 
    6292 
    6393* Use correct `$attachment_id` variable instead of `$id`. 
     
    6696* General code formatting updated. 
    6797 
    68 **Version 0.8** 
     98### Version 0.8 ### 
    6999 
    70100* Inline docs updates. 
     
    79109* Sanitize classes with `sanitize_html_class()`. 
    80110 
    81 **Version 0.7** 
     111### Version 0.7 ### 
    82112 
    83113* Deprecated and replaced functions that lacked the `get_the_image_` prefix. 
     
    85115* Fixed notice when `image_scan` was used. 
    86116 
    87 **Version 0.6.2** 
     117### Version 0.6.2 ### 
    88118 
    89119* Updated the cache to save by post ID instead of a single object. 
    90120* Minor code adjustments. 
    91121 
    92 **Version 0.6.1** 
     122### Version 0.6.1 ### 
    93123 
    94124* Updated inline documentation of the code. 
     
    96126* Set `custom_key` and `default_size` to `null` by default since they're deprecated. 
    97127 
    98 **Version 0.6** 
     128### Version 0.6 ### 
    99129 
    100130* Deprecated `custom_key` in favor of `meta_key`. 
     
    103133* Added a `cache` argument, which allows users to turn off caching. 
    104134 
    105 **Version 0.5** 
     135### Version 0.5 ### 
    106136 
    107137* Added support for persistent-caching plugins. 
     
    111141* Updated the `readme.html` instructions for using the plugin. 
    112142 
    113 **Version 0.4** 
     143### Version 0.4 ### 
    114144 
    115145* Dropped support for older versions of WordPress. Now only compatible with 2.9+. 
     
    119149* Cleaned up some of the old legacy code that's no longer needed. 
    120150 
    121 **Version 0.3.3** 
     151### Version 0.3.3 ### 
    122152 
    123153* General code cleanup 
    124154* Added the `get_the_image` filter hook. 
    125155 
    126 **Version 0.3.2** 
     156### Version 0.3.2 ### 
    127157 
    128158* General code cleanup. 
     
    131161* Added a GPL license.txt file. 
    132162 
    133 **Version 0.3.1** 
     163### Version 0.3.1 ### 
    134164 
    135165* Fixed the default image and image scan features. 
    136166 
    137 **Version 0.3** 
     167### Version 0.3 ### 
    138168 
    139169* Changed methods of calling the image script. 
Note: See TracChangeset for help on using the changeset viewer.