Timber - Version 1.1.11

Version Description

  • Improved flexibility for public query_vars #1250 (thanks @xavivars)
  • Children should inehrit publish state #1255 (thanks @motia)
  • Pages are sorted by their menu order instead of publish order #1251 (thanks @forgandenny)
  • Fixes to object caching #1259
Download this release

Release Info

Developer jarednova
Plugin Icon 128x128 Timber
Version 1.1.11
Comparing to
See all releases

Code changes from version 1.1.10 to 1.1.11

lib/Helper.php CHANGED
@@ -226,6 +226,7 @@ class Helper {
226
  ======================== */
227
 
228
  /**
 
229
  * @deprecated since 1.2.0
230
  * @see TextHelper::trim_words
231
  * @param string $text
@@ -432,7 +433,7 @@ class Helper {
432
  }
433
 
434
  /**
435
- *
436
  * @deprecated since 1.1.2
437
  * @param array $args
438
  * @return array
@@ -443,6 +444,7 @@ class Helper {
443
  }
444
 
445
  /**
 
446
  * @return string
447
  */
448
  public function get_current_url() {
226
  ======================== */
227
 
228
  /**
229
+ * @codeCoverageIgnore
230
  * @deprecated since 1.2.0
231
  * @see TextHelper::trim_words
232
  * @param string $text
433
  }
434
 
435
  /**
436
+ * @codeCoverageIgnore
437
  * @deprecated since 1.1.2
438
  * @param array $args
439
  * @return array
444
  }
445
 
446
  /**
447
+ * @codeCoverageIgnore
448
  * @return string
449
  */
450
  public function get_current_url() {
lib/Image/Operation/Resize.php CHANGED
@@ -7,14 +7,14 @@ use Timber\ImageHelper;
7
  use Timber\Image\Operation as ImageOperation;
8
 
9
  /**
10
- * Changes image to new size, by shrinking/enlarging
11
- * then cropping to respect new ratio.
12
- *
13
- * Arguments:
14
- * - width of new image
15
- * - height of new image
16
- * - crop method
17
- */
18
  class Resize extends ImageOperation {
19
 
20
  private $w, $h, $crop;
7
  use Timber\Image\Operation as ImageOperation;
8
 
9
  /**
10
+ * Changes image to new size, by shrinking/enlarging
11
+ * then cropping to respect new ratio.
12
+ *
13
+ * Arguments:
14
+ * - width of new image
15
+ * - height of new image
16
+ * - crop method
17
+ */
18
  class Resize extends ImageOperation {
19
 
20
  private $w, $h, $crop;
lib/ImageHelper.php CHANGED
@@ -111,7 +111,7 @@ class ImageHelper {
111
  * @return boolean true if it's an animated gif, false if not
112
  */
113
  public static function is_animated_gif( $file ) {
114
- if ( strpos(strtolower($file), '.gif') == -1 ) {
115
  //doesn't have .gif, bail
116
  return false;
117
  }
111
  * @return boolean true if it's an animated gif, false if not
112
  */
113
  public static function is_animated_gif( $file ) {
114
+ if ( strpos(strtolower($file), '.gif') === false ) {
115
  //doesn't have .gif, bail
116
  return false;
117
  }
lib/Loader.php CHANGED
@@ -123,13 +123,15 @@ class Loader {
123
  */
124
  public function get_loader() {
125
  $open_basedir = ini_get('open_basedir');
126
- $paths = array_merge($this->locations, array( $open_basedir ? ABSPATH : '/'));
127
  $paths = apply_filters('timber/loader/paths', $paths);
 
128
  $rootPath = '/';
129
  if ( $open_basedir ) {
130
  $rootPath = null;
131
  }
132
  $fs = new \Twig_Loader_Filesystem($paths, $rootPath);
 
133
  return $fs;
134
  }
135
 
@@ -173,26 +175,34 @@ class Loader {
173
  $object_cache = true;
174
  }
175
  $cache_mode = $this->_get_cache_mode($cache_mode);
176
- if ( self::CACHE_TRANSIENT === $cache_mode ) {
177
- global $wpdb;
178
- $query = $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE '%s'", '_transient_timberloader_%');
179
- $wpdb->query($query);
180
- return true;
181
- } else if ( self::CACHE_SITE_TRANSIENT === $cache_mode ) {
182
- global $wpdb;
183
- $query = $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE '%s'", '_transient_timberloader_%');
184
- $wpdb->query($query);
185
- return true;
186
  } else if ( self::CACHE_OBJECT === $cache_mode && $object_cache ) {
187
- global $wp_object_cache;
188
- if ( isset($wp_object_cache->cache[self::CACHEGROUP]) ) {
189
- unset($wp_object_cache->cache[self::CACHEGROUP]);
190
- return true;
191
- }
192
  }
193
  return false;
194
  }
195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  public function clear_cache_twig() {
197
  $twig = $this->get_twig();
198
  $twig->clearCacheFiles();
123
  */
124
  public function get_loader() {
125
  $open_basedir = ini_get('open_basedir');
126
+ $paths = array_merge($this->locations, array($open_basedir ? ABSPATH : '/'));
127
  $paths = apply_filters('timber/loader/paths', $paths);
128
+
129
  $rootPath = '/';
130
  if ( $open_basedir ) {
131
  $rootPath = null;
132
  }
133
  $fs = new \Twig_Loader_Filesystem($paths, $rootPath);
134
+ $fs = apply_filters('timber/loader/loader', $fs);
135
  return $fs;
136
  }
137
 
175
  $object_cache = true;
176
  }
177
  $cache_mode = $this->_get_cache_mode($cache_mode);
178
+ if ( self::CACHE_TRANSIENT === $cache_mode || self::CACHE_SITE_TRANSIENT === $cache_mode ) {
179
+ return self::clear_cache_timber_database();
 
 
 
 
 
 
 
 
180
  } else if ( self::CACHE_OBJECT === $cache_mode && $object_cache ) {
181
+ return self::clear_cache_timber_object();
 
 
 
 
182
  }
183
  return false;
184
  }
185
 
186
+ protected static function clear_cache_timber_database() {
187
+ global $wpdb;
188
+ $query = $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE '%s'", '_transient_timberloader_%');
189
+ return $wpdb->query($query);
190
+ }
191
+
192
+ protected static function clear_cache_timber_object() {
193
+ global $wp_object_cache;
194
+ if ( isset($wp_object_cache->cache[self::CACHEGROUP]) ) {
195
+ $items = $wp_object_cache->cache[self::CACHEGROUP];
196
+ foreach ( $items as $key => $value ) {
197
+ if ( is_multisite() ) {
198
+ $key = preg_replace('/^(.*?):/', '', $key);
199
+ }
200
+ wp_cache_delete($key, self::CACHEGROUP);
201
+ }
202
+ return true;
203
+ }
204
+ }
205
+
206
  public function clear_cache_twig() {
207
  $twig = $this->get_twig();
208
  $twig->clearCacheFiles();
lib/Menu.php CHANGED
@@ -123,7 +123,7 @@ class Menu extends Core {
123
  * @internal
124
  */
125
  protected function init_as_page_menu() {
126
- $menu = get_pages();
127
  if ( $menu ) {
128
  foreach ( $menu as $mi ) {
129
  $mi->__title = $mi->post_title;
123
  * @internal
124
  */
125
  protected function init_as_page_menu() {
126
+ $menu = get_pages(array('sort_column' => 'menu_order'));
127
  if ( $menu ) {
128
  foreach ( $menu as $mi ) {
129
  $mi->__title = $mi->post_title;
lib/Pagination.php CHANGED
@@ -106,9 +106,14 @@ class Pagination {
106
  * @return boolean
107
  */
108
  public static function is_search_query( $url ) {
109
- if ( strpos($url, 's=') !== false ) {
110
- return true;
 
 
 
 
111
  }
 
112
  return false;
113
  }
114
 
@@ -161,17 +166,20 @@ class Pagination {
161
  if ( $args['show_all'] || ($n <= $args['end_size'] || ($args['current'] && $n >= $args['current'] - $args['mid_size'] && $n <= $args['current'] + $args['mid_size']) || $n > $args['total'] - $args['end_size']) ) {
162
  $link = str_replace('%_%', 1 == $n ? '' : $args['format'], $args['base']);
163
  $link = str_replace('%#%', $n, $link);
164
- $link = trailingslashit($link).ltrim($args['add_fragment'], '/');
 
 
 
 
165
  if ( $args['add_args'] ) {
166
- $link = rtrim(add_query_arg($args['add_args'], $link), '/');
167
  }
168
- $link = str_replace(' ', '+', $link);
169
- $link = untrailingslashit($link);
 
 
170
  $link = esc_url(apply_filters('paginate_links', $link));
171
- $link = user_trailingslashit($link);
172
- if ( self::is_search_query($link) ) {
173
- $link = untrailingslashit($link);
174
- }
175
  $page_links[] = array(
176
  'class' => 'page-number page-numbers',
177
  'link' => $link,
106
  * @return boolean
107
  */
108
  public static function is_search_query( $url ) {
109
+ global $wp;
110
+
111
+ foreach( $wp->public_query_vars as $public_query_var ) {
112
+ if ( strpos($url, $public_query_var.'=') !== false ) {
113
+ return true;
114
+ }
115
  }
116
+
117
  return false;
118
  }
119
 
166
  if ( $args['show_all'] || ($n <= $args['end_size'] || ($args['current'] && $n >= $args['current'] - $args['mid_size'] && $n <= $args['current'] + $args['mid_size']) || $n > $args['total'] - $args['end_size']) ) {
167
  $link = str_replace('%_%', 1 == $n ? '' : $args['format'], $args['base']);
168
  $link = str_replace('%#%', $n, $link);
169
+
170
+ // we first follow the user trailing slash configuration
171
+ $link = user_trailingslashit($link);
172
+
173
+ // then we add all required querystring parameters
174
  if ( $args['add_args'] ) {
175
+ $link = add_query_arg($args['add_args'], $link);
176
  }
177
+
178
+ // last, we add fragment if needed
179
+ $link .= $args['add_fragment'];
180
+
181
  $link = esc_url(apply_filters('paginate_links', $link));
182
+
 
 
 
183
  $page_links[] = array(
184
  'class' => 'page-number page-numbers',
185
  'link' => $link,
lib/Post.php CHANGED
@@ -849,7 +849,10 @@ class Post extends Core implements CoreInterface {
849
  if ( is_array($post_type) ) {
850
  $post_type = implode('&post_type[]=', $post_type);
851
  }
852
- $query = 'post_parent='.$this->ID.'&post_type[]='.$post_type.'&numberposts=-1&orderby=menu_order title&order=ASC&post_status=publish';
 
 
 
853
  $children = get_children($query);
854
  foreach ( $children as &$child ) {
855
  $child = new $childPostClass($child->ID);
849
  if ( is_array($post_type) ) {
850
  $post_type = implode('&post_type[]=', $post_type);
851
  }
852
+ $query = 'post_parent='.$this->ID.'&post_type[]='.$post_type.'&numberposts=-1&orderby=menu_order title&order=ASC&post_status[]=publish';
853
+ if ( $this->post_status == 'publish' ) {
854
+ $query .= '&post_status[]=inherit';
855
+ }
856
  $children = get_children($query);
857
  foreach ( $children as &$child ) {
858
  $child = new $childPostClass($child->ID);
lib/Timber.php CHANGED
@@ -35,7 +35,7 @@ use Timber\Loader;
35
  */
36
  class Timber {
37
 
38
- public static $version = '1.1.10';
39
  public static $locations;
40
  public static $dirname = 'views';
41
  public static $twig_cache = false;
@@ -420,7 +420,6 @@ class Timber {
420
  /* Utility
421
  ================================ */
422
 
423
-
424
  /**
425
  * Add route.
426
  *
@@ -428,6 +427,7 @@ class Timber {
428
  * @param callable $callback
429
  * @param array $args
430
  * @deprecated since 0.20.0 and will be removed in 1.1
 
431
  */
432
  public static function add_route( $route, $callback, $args = array() ) {
433
  Helper::warn('Timber::add_route (and accompanying methods for load_view, etc. Have been deprecated and will soon be removed. Please update your theme with Route::map. You can read more in the 1.0 Upgrade Guide: https://github.com/timber/timber/wiki/1.0-Upgrade-Guide');
35
  */
36
  class Timber {
37
 
38
+ public static $version = '1.1.11';
39
  public static $locations;
40
  public static $dirname = 'views';
41
  public static $twig_cache = false;
420
  /* Utility
421
  ================================ */
422
 
 
423
  /**
424
  * Add route.
425
  *
427
  * @param callable $callback
428
  * @param array $args
429
  * @deprecated since 0.20.0 and will be removed in 1.1
430
+ * @codeCoverageIgnore
431
  */
432
  public static function add_route( $route, $callback, $args = array() ) {
433
  Helper::warn('Timber::add_route (and accompanying methods for load_view, etc. Have been deprecated and will soon be removed. Please update your theme with Route::map. You can read more in the 1.0 Upgrade Guide: https://github.com/timber/timber/wiki/1.0-Upgrade-Guide');
lib/Twig.php CHANGED
@@ -318,7 +318,7 @@ class Twig {
318
  * @param string $format_future
319
  * @return string
320
  */
321
- public function time_ago( $from, $to = null, $format_past = '%s ago', $format_future = '%s from now' ) {
322
  $to = $to === null ? time() : $to;
323
  $to = is_int($to) ? $to : strtotime($to);
324
  $from = is_int($from) ? $from : strtotime($from);
318
  * @param string $format_future
319
  * @return string
320
  */
321
+ public static function time_ago( $from, $to = null, $format_past = '%s ago', $format_future = '%s from now' ) {
322
  $to = $to === null ? time() : $to;
323
  $to = is_int($to) ? $to : strtotime($to);
324
  $from = is_int($from) ? $from : strtotime($from);
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.10
6
  Tested up to: 4.6
7
  PHP version: 5.3.0 or greater
8
  License: GPLv2 or later
@@ -41,6 +41,12 @@ Timber is great for any WordPress developer who cares about writing good, mainta
41
 
42
  == Changelog ==
43
 
 
 
 
 
 
 
44
  = 1.1.10 =
45
  * Added support for Co-Authors Plus Guest Authors #1239 (thanks @motia)
46
  * Fix for Yoast SEO with multisite #1244 (thanks @alexandernanberg)
2
  Contributors: jarednova, connorjburton, lggorman
3
  Tags: template engine, templates, twig
4
  Requires at least: 3.7
5
+ Stable tag: 1.1.11
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.11 =
45
+ * Improved flexibility for public query_vars #1250 (thanks @xavivars)
46
+ * Children should inehrit publish state #1255 (thanks @motia)
47
+ * Pages are sorted by their menu order instead of publish order #1251 (thanks @forgandenny)
48
+ * Fixes to object caching #1259
49
+
50
  = 1.1.10 =
51
  * Added support for Co-Authors Plus Guest Authors #1239 (thanks @motia)
52
  * Fix for Yoast SEO with multisite #1244 (thanks @alexandernanberg)
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.10
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.11
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 ComposerAutoloaderInitcf447073f6657b2ba7aa1f473b8d19ac::getLoader();
4
 
5
  require_once __DIR__ . '/composer' . '/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInit169e0829974ac43c7824bc524908c054::getLoader();
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInitcf447073f6657b2ba7aa1f473b8d19ac
6
  {
7
  private static $loader;
8
 
@@ -19,9 +19,9 @@ class ComposerAutoloaderInitcf447073f6657b2ba7aa1f473b8d19ac
19
  return self::$loader;
20
  }
21
 
22
- spl_autoload_register(array('ComposerAutoloaderInitcf447073f6657b2ba7aa1f473b8d19ac', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
- spl_autoload_unregister(array('ComposerAutoloaderInitcf447073f6657b2ba7aa1f473b8d19ac', 'loadClassLoader'));
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 ComposerAutoloaderInit169e0829974ac43c7824bc524908c054
6
  {
7
  private static $loader;
8
 
19
  return self::$loader;
20
  }
21
 
22
+ spl_autoload_register(array('ComposerAutoloaderInit169e0829974ac43c7824bc524908c054', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
+ spl_autoload_unregister(array('ComposerAutoloaderInit169e0829974ac43c7824bc524908c054', 'loadClassLoader'));
25
 
26
  $map = require __DIR__ . '/autoload_namespaces.php';
27
  foreach ($map as $namespace => $path) {