Version Description
- Fixed image generation when images are updated/deleted by WordPress (thanks @dudewithamood)
Download this release
Release Info
Developer | jarednova |
Plugin | Timber |
Version | 1.1.8 |
Comparing to | |
See all releases |
Code changes from version 1.1.7.1 to 1.1.8
- lib/ImageHelper.php +31 -15
- lib/Timber.php +1 -1
- readme.txt +5 -2
- timber-starter-theme/functions.php +1 -1
- timber.php +1 -1
- vendor/autoload.php +1 -1
- vendor/composer/autoload_real.php +3 -3
lib/ImageHelper.php
CHANGED
@@ -167,18 +167,16 @@ class ImageHelper {
|
|
167 |
|
168 |
/**
|
169 |
* Deletes all resized versions of an image when the source is deleted
|
|
|
170 |
*/
|
171 |
protected static function add_actions() {
|
172 |
add_action('delete_attachment', function( $post_id ) {
|
173 |
-
|
174 |
-
$image_types = array('image/jpeg', 'image/png', 'image/gif', 'image/jpg');
|
175 |
-
if ( in_array($post->post_mime_type, $image_types) ) {
|
176 |
-
$attachment = new Image($post_id);
|
177 |
-
if ( $attachment->file_loc ) {
|
178 |
-
ImageHelper::delete_generated_files($attachment->file_loc);
|
179 |
-
}
|
180 |
-
}
|
181 |
} );
|
|
|
|
|
|
|
|
|
182 |
}
|
183 |
|
184 |
/**
|
@@ -205,6 +203,24 @@ class ImageHelper {
|
|
205 |
}
|
206 |
|
207 |
//-- end of public methods --//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
/**
|
209 |
* Deletes the auto-generated files for resize and letterboxing created by Timber
|
210 |
* @param string $local_file ex: /var/www/wp-content/uploads/2015/my-pic.jpg
|
@@ -458,32 +474,32 @@ class ImageHelper {
|
|
458 |
$op->filename($au['filename'], $au['extension']),
|
459 |
$au['absolute']
|
460 |
);
|
461 |
-
$
|
462 |
$au['base'],
|
463 |
$au['subdir'],
|
464 |
$op->filename($au['filename'], $au['extension'])
|
465 |
);
|
466 |
-
$
|
467 |
$au['base'],
|
468 |
$au['subdir'],
|
469 |
$au['basename']
|
470 |
);
|
471 |
|
472 |
$new_url = apply_filters('timber/image/new_url', $new_url);
|
473 |
-
$
|
474 |
|
475 |
// if already exists...
|
476 |
-
if ( file_exists($
|
477 |
-
if ( $force ) {
|
478 |
// Force operation - warning: will regenerate the image on every pageload, use for testing purposes only!
|
479 |
-
unlink($
|
480 |
} else {
|
481 |
// return existing file (caching)
|
482 |
return $new_url;
|
483 |
}
|
484 |
}
|
485 |
// otherwise generate result file
|
486 |
-
if ( $op->run($
|
487 |
if ( get_class($op) === 'Timber\Image\Operation\Resize' && $external ) {
|
488 |
$new_url = strtolower($new_url);
|
489 |
}
|
167 |
|
168 |
/**
|
169 |
* Deletes all resized versions of an image when the source is deleted
|
170 |
+
* or its meta data is regenerated
|
171 |
*/
|
172 |
protected static function add_actions() {
|
173 |
add_action('delete_attachment', function( $post_id ) {
|
174 |
+
\Timber\ImageHelper::_delete_generated_if_image($post_id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
} );
|
176 |
+
add_filter('wp_generate_attachment_metadata', function( $metadata, $post_id ) {
|
177 |
+
\Timber\ImageHelper::_delete_generated_if_image($post_id);
|
178 |
+
return $metadata;
|
179 |
+
}, 10, 2);
|
180 |
}
|
181 |
|
182 |
/**
|
203 |
}
|
204 |
|
205 |
//-- end of public methods --//
|
206 |
+
|
207 |
+
|
208 |
+
/**
|
209 |
+
* Checks if attachment is an image before deleting generated files
|
210 |
+
*
|
211 |
+
* @param int $post_id an attachment post id
|
212 |
+
*
|
213 |
+
*/
|
214 |
+
public static function _delete_generated_if_image( $post_id ) {
|
215 |
+
if ( wp_attachment_is_image($post_id) ) {
|
216 |
+
$attachment = new Image($post_id);
|
217 |
+
if ( $attachment->file_loc ) {
|
218 |
+
ImageHelper::delete_generated_files($attachment->file_loc);
|
219 |
+
}
|
220 |
+
}
|
221 |
+
}
|
222 |
+
|
223 |
+
|
224 |
/**
|
225 |
* Deletes the auto-generated files for resize and letterboxing created by Timber
|
226 |
* @param string $local_file ex: /var/www/wp-content/uploads/2015/my-pic.jpg
|
474 |
$op->filename($au['filename'], $au['extension']),
|
475 |
$au['absolute']
|
476 |
);
|
477 |
+
$destination_path = self::_get_file_path(
|
478 |
$au['base'],
|
479 |
$au['subdir'],
|
480 |
$op->filename($au['filename'], $au['extension'])
|
481 |
);
|
482 |
+
$source_path = self::_get_file_path(
|
483 |
$au['base'],
|
484 |
$au['subdir'],
|
485 |
$au['basename']
|
486 |
);
|
487 |
|
488 |
$new_url = apply_filters('timber/image/new_url', $new_url);
|
489 |
+
$destination_path = apply_filters('timber/image/new_path', $destination_path);
|
490 |
|
491 |
// if already exists...
|
492 |
+
if ( file_exists($destination_path) ) {
|
493 |
+
if ( $force || filemtime($source_path) > filemtime($destination_path) ) {
|
494 |
// Force operation - warning: will regenerate the image on every pageload, use for testing purposes only!
|
495 |
+
unlink($destination_path);
|
496 |
} else {
|
497 |
// return existing file (caching)
|
498 |
return $new_url;
|
499 |
}
|
500 |
}
|
501 |
// otherwise generate result file
|
502 |
+
if ( $op->run($source_path, $destination_path) ) {
|
503 |
if ( get_class($op) === 'Timber\Image\Operation\Resize' && $external ) {
|
504 |
$new_url = strtolower($new_url);
|
505 |
}
|
lib/Timber.php
CHANGED
@@ -35,7 +35,7 @@ use Timber\Loader;
|
|
35 |
*/
|
36 |
class Timber {
|
37 |
|
38 |
-
public static $version = '1.1.
|
39 |
public static $locations;
|
40 |
public static $dirname = 'views';
|
41 |
public static $twig_cache = false;
|
35 |
*/
|
36 |
class Timber {
|
37 |
|
38 |
+
public static $version = '1.1.8';
|
39 |
public static $locations;
|
40 |
public static $dirname = 'views';
|
41 |
public static $twig_cache = false;
|
readme.txt
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
Contributors: jarednova, connorjburton, lggorman
|
3 |
Tags: template engine, templates, twig
|
4 |
Requires at least: 3.7
|
5 |
-
Stable tag: 1.1.
|
6 |
Tested up to: 4.6
|
7 |
PHP version: 5.3.0 or greater
|
8 |
License: GPLv2 or later
|
@@ -41,8 +41,11 @@ Timber is great for any WordPress developer who cares about writing good, mainta
|
|
41 |
|
42 |
== Changelog ==
|
43 |
|
|
|
|
|
|
|
44 |
= 1.1.7.1 =
|
45 |
-
* Quick fix for backwards
|
46 |
|
47 |
= 1.1.7 =
|
48 |
* A new PostQuery object that comes _with_ pagination (thanks @lggorman).
|
2 |
Contributors: jarednova, connorjburton, lggorman
|
3 |
Tags: template engine, templates, twig
|
4 |
Requires at least: 3.7
|
5 |
+
Stable tag: 1.1.8
|
6 |
Tested up to: 4.6
|
7 |
PHP version: 5.3.0 or greater
|
8 |
License: GPLv2 or later
|
41 |
|
42 |
== Changelog ==
|
43 |
|
44 |
+
= 1.1.8 =
|
45 |
+
* Fixed image generation when images are updated/deleted by WordPress (thanks @dudewithamood)
|
46 |
+
|
47 |
= 1.1.7.1 =
|
48 |
+
* Quick fix for backwards compatibility in some situations
|
49 |
|
50 |
= 1.1.7 =
|
51 |
* A new PostQuery object that comes _with_ pagination (thanks @lggorman).
|
timber-starter-theme/functions.php
CHANGED
@@ -45,7 +45,7 @@ class StarterSite extends TimberSite {
|
|
45 |
}
|
46 |
|
47 |
function add_to_twig( $twig ) {
|
48 |
-
/* this is where you can add your own
|
49 |
$twig->addExtension( new Twig_Extension_StringLoader() );
|
50 |
$twig->addFilter('myfoo', new Twig_SimpleFilter('myfoo', array($this, 'myfoo')));
|
51 |
return $twig;
|
45 |
}
|
46 |
|
47 |
function add_to_twig( $twig ) {
|
48 |
+
/* this is where you can add your own functions to twig */
|
49 |
$twig->addExtension( new Twig_Extension_StringLoader() );
|
50 |
$twig->addFilter('myfoo', new Twig_SimpleFilter('myfoo', array($this, 'myfoo')));
|
51 |
return $twig;
|
timber.php
CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Timber
|
|
4 |
Description: The WordPress Timber Library allows you to write themes using the power Twig templates.
|
5 |
Plugin URI: http://timber.upstatement.com
|
6 |
Author: Jared Novack + Upstatement
|
7 |
-
Version: 1.1.
|
8 |
Author URI: http://upstatement.com/
|
9 |
*/
|
10 |
// we look for Composer files first in the plugins dir.
|
4 |
Description: The WordPress Timber Library allows you to write themes using the power Twig templates.
|
5 |
Plugin URI: http://timber.upstatement.com
|
6 |
Author: Jared Novack + Upstatement
|
7 |
+
Version: 1.1.8
|
8 |
Author URI: http://upstatement.com/
|
9 |
*/
|
10 |
// we look for Composer files first in the plugins dir.
|
vendor/autoload.php
CHANGED
@@ -4,4 +4,4 @@
|
|
4 |
|
5 |
require_once __DIR__ . '/composer' . '/autoload_real.php';
|
6 |
|
7 |
-
return
|
4 |
|
5 |
require_once __DIR__ . '/composer' . '/autoload_real.php';
|
6 |
|
7 |
+
return ComposerAutoloaderInita8a20583fdb84a7c5284a224ce4e2214::getLoader();
|
vendor/composer/autoload_real.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
// autoload_real.php @generated by Composer
|
4 |
|
5 |
-
class
|
6 |
{
|
7 |
private static $loader;
|
8 |
|
@@ -19,9 +19,9 @@ class ComposerAutoloaderInitdae43dd1a50d8989e445dd31133cbde0
|
|
19 |
return self::$loader;
|
20 |
}
|
21 |
|
22 |
-
spl_autoload_register(array('
|
23 |
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
24 |
-
spl_autoload_unregister(array('
|
25 |
|
26 |
$map = require __DIR__ . '/autoload_namespaces.php';
|
27 |
foreach ($map as $namespace => $path) {
|
2 |
|
3 |
// autoload_real.php @generated by Composer
|
4 |
|
5 |
+
class ComposerAutoloaderInita8a20583fdb84a7c5284a224ce4e2214
|
6 |
{
|
7 |
private static $loader;
|
8 |
|
19 |
return self::$loader;
|
20 |
}
|
21 |
|
22 |
+
spl_autoload_register(array('ComposerAutoloaderInita8a20583fdb84a7c5284a224ce4e2214', 'loadClassLoader'), true, true);
|
23 |
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
24 |
+
spl_autoload_unregister(array('ComposerAutoloaderInita8a20583fdb84a7c5284a224ce4e2214', 'loadClassLoader'));
|
25 |
|
26 |
$map = require __DIR__ . '/autoload_namespaces.php';
|
27 |
foreach ($map as $namespace => $path) {
|