Skip to content

Commit

Permalink
Bringing in version 1.0.0 of the Get the Image script.
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Tadlock committed Jul 10, 2014
1 parent 3cf78b8 commit 89cc5f2
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions extensions/get-the-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @package GetTheImage
* @version 1.0.0-alpha-1
* @version 1.0.0
* @author Justin Tadlock <justin@justintadlock.com>
* @copyright Copyright (c) 2008 - 2013, Justin Tadlock
* @copyright Copyright (c) 2008 - 2014, Justin Tadlock
* @link http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
Expand Down Expand Up @@ -110,6 +110,11 @@ final class Get_The_Image {
* @return void
*/
public function __construct( $args = array() ) {
global $wp_embed;

/* Use WP's embed functionality to handle the [embed] shortcode and autoembeds. */
add_filter( 'get_the_image_post_content', array( $wp_embed, 'run_shortcode' ) );
add_filter( 'get_the_image_post_content', array( $wp_embed, 'autoembed' ) );

/* Set the default arguments. */
$defaults = array(
Expand Down Expand Up @@ -143,6 +148,10 @@ public function __construct( $args = array() ) {
'before' => '',
'after' => '',

/* Minimum allowed sizes. */
'min_width' => 0,
'min_height' => 0,

/* Captions. */
'caption' => false, // Default WP [caption] requires a width.

Expand Down Expand Up @@ -207,7 +216,7 @@ public function __construct( $args = array() ) {

/* Only used if $original_image is set. */
if ( true === $this->args['split_content'] && !empty( $this->original_image ) )
add_filter( 'the_content', array( $this, 'split_content' ), 1 );
add_filter( 'the_content', array( $this, 'split_content' ), 15 );
}

/**
Expand Down Expand Up @@ -443,6 +452,9 @@ public function get_scan_image() {
/* Get the post content. */
$post_content = get_post_field( 'post_content', $this->args['post_id'] );

/* Apply filters to content. */
$post_content = apply_filters( 'get_the_image_post_content', $post_content );

/* Check the content for `id="wp-image-%d"`. */
preg_match( '/id=[\'"]wp-image-([\d]*)[\'"]/i', $post_content, $image_ids );

Expand Down Expand Up @@ -488,6 +500,9 @@ public function get_scan_raw_image() {
/* Get the post content. */
$post_content = get_post_field( 'post_content', $this->args['post_id'] );

/* Apply filters to content. */
$post_content = apply_filters( 'get_the_image_post_content', $post_content );

/* Finds matches for shortcodes in the content. */
preg_match_all( '/' . get_shortcode_regex() . '/s', $post_content, $matches, PREG_SET_ORDER );

Expand Down Expand Up @@ -627,6 +642,14 @@ public function format_image() {
if ( empty( $this->image_args['src'] ) )
return;

/* Check against min. width. If the image width is too small return. */
if ( 0 < $this->args['min_width'] && isset( $this->image_args['width'] ) && $this->image_args['width'] < $this->args['min_width'] )
return;

/* Check against min. height. If the image height is too small return. */
if ( 0 < $this->args['min_height'] && isset( $this->image_args['height'] ) && $this->image_args['height'] < $this->args['min_height'] )
return;

/* Empty classes array. */
$classes = array();

Expand Down

0 comments on commit 89cc5f2

Please sign in to comment.