Skip to content

Commit

Permalink
Merge pull request #21 from justcoded/develop
Browse files Browse the repository at this point in the history
Compatibility with JIO, Regenerate thumbnails
  • Loading branch information
aprokopenko authored Mar 15, 2018
2 parents 6a28821 + aaf51f4 commit 0819eca
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/MediaMetaInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function add_meta_boxes( $post ) {
*/
public function render_meta_info( $post ) {
$meta = wp_get_attachment_metadata( $post->ID );

if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
$meta['gcd'] = jri_greatest_commod_divisor( $meta['width'], $meta['height'] );
$meta['x_ratio'] = (int) $meta['width'] / $meta['gcd'];
Expand Down
28 changes: 25 additions & 3 deletions components/PostAttachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace jri\components;

use jri\models\RwdSet;
use jri\models\ImageSize;

/**
* Patch standard <img> "srcset" attribute generation
Expand Down Expand Up @@ -35,7 +36,7 @@ public function add_image_responsive_hooks() {
add_filter( 'wp_get_attachment_image_src', array( $this, 'set_calculated_image_size_cache' ), 10, 4 );
add_filter( 'wp_calculate_image_srcset', array( $this, 'calculate_image_srcset' ), 10, 5 );
add_filter( 'wp_calculate_image_sizes', array( $this, 'calculate_image_sizes' ), 10, 5 );
add_filter( 'intermediate_image_sizes', array( $this, 'unify_wp_image_sizes' ) );
add_filter( 'jio_settings_image_sizes', array( $this, 'add_jio_image_sizes' ) );
}

/**
Expand Down Expand Up @@ -219,8 +220,29 @@ public function attachment_image_attributes( $attr, $attachment, $size ) {
*
* @return mixed
*/
public function unify_wp_image_sizes( $image_sizes ) {
$image_sizes = array_unique( $image_sizes );
public function add_jio_image_sizes( $image_sizes ) {
global $rwd_image_options;
foreach ( $rwd_image_options as $subkey => $option ) {

$image_sizes[ $subkey ] = array(
'width' => $option->size->w,
'height' => $option->size->h,
'crop' => $option->size->crop,
);

if ( $option->retina_options ) {
foreach ( $option->retina_options as $retina_descriptor => $multiplier ) {
$retina_key = ImageSize::get_retina_key( $option->key, $retina_descriptor );

$image_sizes[ $retina_key ] = array(
'width' => $option->size->w * $multiplier,
'height' => $option->size->h * $multiplier,
'crop' => $option->size->crop,
);
}
}
}

return $image_sizes;
}

Expand Down
4 changes: 2 additions & 2 deletions just-responsive-images.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin Name: Just Responsive Images
Description: Providing full control to set your own responsive image properties for WordPress 4.4+, the ability to use the &lt;picture&gt; tag, auto-generate image backgrounds and supports retina images.
Tags: responsive post thumbnail, post thumbnail as background, retina support, retina image, retina post thumbnail, responsive post attachment, responsive images, responsive attachments, post thumbnails, media
Version: 1.4.1
Version: 1.5
Author: JustCoded / Alex Prokopenko
Author URI: http://justcoded.com/
License: GPL3
Expand Down Expand Up @@ -49,7 +49,7 @@ class JustResponsiveImages extends core\Singleton {
protected function __construct() {
// init plugin name and version.
self::$plugin_name = __( 'Just Responsive Images', JustResponsiveImages::TEXTDOMAIN );
self::$version = 1.401;
self::$version = '1.500';

// init features, which this plugin is created for.
new components\Maintenance();
Expand Down
1 change: 1 addition & 0 deletions models/ImageSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function register() {
update_site_option( "{$this->key}_size_w", $this->w );
update_site_option( "{$this->key}_size_h", $this->h );
update_site_option( "{$this->key}_crop", ! empty( $this->crop ) );
add_image_size( $this->key, $this->w, $this->h, $this->crop );
}
}

Expand Down
8 changes: 8 additions & 0 deletions models/RwdImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ class RwdImage {
*/
protected $eol = "\n";

/**
* JIO Attachment status in queue
*
* @var int
*/
const STATUS_IN_QUEUE = 1;

/**
* RwdImage constructor.
Expand Down Expand Up @@ -556,6 +562,8 @@ public function resize_image( $attach_id, $meta_data, $key, $width, $height, $cr
$this->set_attachment_metadata( $attach_id, $meta_data );
// update metadata.
wp_update_attachment_metadata( $attach_id, $meta_data );
// update JIO attachment status
update_post_meta( $attach_id, '_just_img_opt_status', self::STATUS_IN_QUEUE );
}
}

Expand Down
2 changes: 2 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ There are no any special upgrade instructions for version 1.0 - 1.3
To upgrade remove the old plugin folder. After than follow the installation steps 1-2.

== Changelog ==
= Version 1.5 - 15 March 2018 =
* Added compatibility with Just Image Optimizer plugin
= Version 1.4.1 - 9 March 2018 =
* Bug fix: Wrong image source taken when image crop enabled and original width/height is the same and required height/width are less than origin.
= Version 1.4 - 7 March 2018 =
Expand Down

0 comments on commit 0819eca

Please sign in to comment.