Timber - Version 0.22.1

Version Description

  • Added better support for post.get_terms (thanks @aaemnnosttv)
  • Fix for issue with ACF date field (thanks @rpkoller)
  • Fix for resizing jpEgs (thanks @eaton)
Download this release

Release Info

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

Code changes from version 0.22.0 to 0.22.1

lib/image/timber-image-operation-tojpg.php CHANGED
@@ -58,9 +58,15 @@ class TimberImageOperationToJpg extends TimberImageOperation {
58
  $ext = $ext['ext'];
59
  }
60
  }
 
61
  if ( $ext == 'gif' ) {
62
  return imagecreatefromgif($filename);
63
  }
64
- return imagecreatefrompng($filename);
 
 
 
 
 
65
  }
66
  }
58
  $ext = $ext['ext'];
59
  }
60
  }
61
+ $ext = strtolower($ext);
62
  if ( $ext == 'gif' ) {
63
  return imagecreatefromgif($filename);
64
  }
65
+ if ( $ext == 'png' ) {
66
+ return imagecreatefrompng($filename);
67
+ }
68
+ if ( $ext == 'jpg' || $ext == 'jpeg') {
69
+ return imagecreatefromjpeg($filename);
70
+ }
71
  }
72
  }
lib/timber-archives.php CHANGED
@@ -94,7 +94,7 @@ class TimberArchives extends TimberCore {
94
  protected function get_items_yearly( $args, $last_changed, $join, $where, $order, $limit ) {
95
  global $wpdb;
96
  $output = array();
97
- $query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit";
98
  $key = md5($query);
99
  $key = "wp_get_archives:$key:$last_changed";
100
  if (!$results = wp_cache_get($key, 'posts')) {
@@ -226,7 +226,8 @@ class TimberArchives extends TimberCore {
226
  $archive_week_end_date_format = get_option('date_format');
227
  }
228
 
229
- $where = apply_filters('getarchives_where', 'WHERE post_type = "' . $post_type . '" AND post_status = "publish"', $args);
 
230
  $join = apply_filters('getarchives_join', '', $args);
231
 
232
  $output = array();
94
  protected function get_items_yearly( $args, $last_changed, $join, $where, $order, $limit ) {
95
  global $wpdb;
96
  $output = array();
97
+ $query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM {$wpdb->posts} $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit";
98
  $key = md5($query);
99
  $key = "wp_get_archives:$key:$last_changed";
100
  if (!$results = wp_cache_get($key, 'posts')) {
226
  $archive_week_end_date_format = get_option('date_format');
227
  }
228
 
229
+ $where = $wpdb->prepare('WHERE post_type = "%s" AND post_status = "publish"', $post_type);
230
+ $where = apply_filters('getarchives_where', $where, $args);
231
  $join = apply_filters('getarchives_join', '', $args);
232
 
233
  $output = array();
lib/timber-post.php CHANGED
@@ -44,6 +44,11 @@ class TimberPost extends TimberCore implements TimberCoreInterface {
44
  */
45
  public $PostClass = 'TimberPost';
46
 
 
 
 
 
 
47
  /**
48
  * @var string $object_type what does this class represent in WordPress terms?
49
  */
@@ -63,6 +68,7 @@ class TimberPost extends TimberCore implements TimberCoreInterface {
63
  /**
64
  * @internal
65
  * @var array $_get_terms stores the results of a get_terms method call
 
66
  */
67
  protected $_get_terms;
68
 
@@ -773,56 +779,63 @@ class TimberPost extends TimberCore implements TimberCoreInterface {
773
 
774
  /**
775
  * @internal
776
- * @param string $tax
777
  * @param bool $merge
778
  * @param string $TermClass
779
  * @return array
780
  */
781
- function get_terms( $tax = '', $merge = true, $TermClass = 'TimberTerm' ) {
 
 
 
782
  if ( is_string($merge) && class_exists($merge) ) {
783
  $TermClass = $merge;
784
  }
 
 
 
785
  if ( is_string($tax) ) {
786
- if ( isset($this->_get_terms) && isset($this->_get_terms[$tax]) ) {
787
- return $this->_get_terms[$tax];
 
 
788
  }
789
  }
790
- if ( !strlen($tax) || $tax == 'all' || $tax == 'any' ) {
791
- $taxs = get_object_taxonomies($this->post_type);
792
- } else if ( is_array($tax) ) {
793
- $taxs = $tax;
794
- } else {
795
- $taxs = array($tax);
796
- }
797
- $ret = array();
798
- foreach ( $taxs as $tax ) {
799
- if ( $tax == 'tags' || $tax == 'tag' ) {
800
- $tax = 'post_tag';
801
- } else if ( $tax == 'categories' ) {
802
- $tax = 'category';
803
  }
804
- $terms = wp_get_post_terms($this->ID, $tax);
805
- if ( !is_array($terms) && is_object($terms) && get_class($terms) == 'WP_Error' ) {
806
- //something is very wrong
807
- TimberHelper::error_log('You have an error retrieving terms on a post in timber-post.php:628');
808
- TimberHelper::error_log('tax = ' . $tax);
809
- TimberHelper::error_log($terms);
810
- } else {
811
- foreach ( $terms as &$term ) {
812
- $term = new $TermClass($term->term_id, $tax);
813
- }
814
- if ( $merge && is_array($terms) ) {
815
- $ret = array_merge($ret, $terms);
816
- } else if ( count($terms) ) {
817
- $ret[$tax] = $terms;
818
- }
 
 
 
 
 
 
 
 
 
819
  }
820
  }
821
- if ( !isset($this->_get_terms) ) {
822
- $this->_get_terms = array();
823
- }
824
- $this->_get_terms[$tax] = $ret;
825
- return $ret;
826
  }
827
 
828
  /**
@@ -867,7 +880,7 @@ class TimberPost extends TimberCore implements TimberCoreInterface {
867
  * @return array
868
  */
869
  function get_tags() {
870
- return $this->get_terms('tags');
871
  }
872
 
873
  /**
@@ -1326,7 +1339,7 @@ class TimberPost extends TimberCore implements TimberCoreInterface {
1326
  * Get the terms associated with the post
1327
  * This goes across all taxonomies by default
1328
  * @api
1329
- * @param string $tax What taxonomy to pull from, defaults to all of them. You can use custom ones, or built-in WordPress taxonomies (category, tag). Timber plays nice and figures out that tag/tags/post_tag are all the same (and categories/category), for custom taxonomies you're on your own.
1330
  * @param bool $merge Should the resulting array be one big one (true)? Or should it be an array of sub-arrays for each taxonomy (false)?
1331
  * @return array
1332
  */
44
  */
45
  public $PostClass = 'TimberPost';
46
 
47
+ /**
48
+ * @var string $TermClass the name of the class to handle terms by default
49
+ */
50
+ public $TermClass = 'TimberTerm';
51
+
52
  /**
53
  * @var string $object_type what does this class represent in WordPress terms?
54
  */
68
  /**
69
  * @internal
70
  * @var array $_get_terms stores the results of a get_terms method call
71
+ * @deprecated
72
  */
73
  protected $_get_terms;
74
 
779
 
780
  /**
781
  * @internal
782
+ * @param string|array $tax
783
  * @param bool $merge
784
  * @param string $TermClass
785
  * @return array
786
  */
787
+ function get_terms( $tax = '', $merge = true, $TermClass = '' ) {
788
+
789
+ $TermClass = $TermClass ?: $this->TermClass;
790
+
791
  if ( is_string($merge) && class_exists($merge) ) {
792
  $TermClass = $merge;
793
  }
794
+ if ( is_array($tax) ) {
795
+ $taxonomies = $tax;
796
+ }
797
  if ( is_string($tax) ) {
798
+ if ( in_array($tax, array('all','any','')) ) {
799
+ $taxonomies = get_object_taxonomies($this->post_type);
800
+ } else {
801
+ $taxonomies = array($tax);
802
  }
803
  }
804
+
805
+ $term_class_objects = array();
806
+
807
+ foreach ( $taxonomies as $taxonomy ) {
808
+ if ( in_array($taxonomy, array('tag','tags')) ) {
809
+ $taxonomy = 'post_tag';
 
 
 
 
 
 
 
810
  }
811
+ if ( $taxonomy == 'categories' ) {
812
+ $taxonomy = 'category';
813
+ }
814
+
815
+ $terms = wp_get_post_terms($this->ID, $taxonomy);
816
+
817
+ if ( is_wp_error($terms) ) {
818
+ /* @var $terms WP_Error */
819
+ TimberHelper::error_log("Error retrieving terms for taxonomy '$taxonomy' on a post in timber-post.php");
820
+ TimberHelper::error_log('tax = ' . print_r($tax, true));
821
+ TimberHelper::error_log('WP_Error: ' . $terms->get_error_message());
822
+
823
+ return $term_class_objects;
824
+ }
825
+
826
+ // map over array of wordpress terms, and transform them into instances of the TermClass
827
+ $terms = array_map(function($term) use ($TermClass, $taxonomy) {
828
+ return call_user_func(array($TermClass, 'from'), $term->term_id, $taxonomy);
829
+ }, $terms);
830
+
831
+ if ( $merge && is_array($terms) ) {
832
+ $term_class_objects = array_merge($term_class_objects, $terms);
833
+ } else if ( count($terms) ) {
834
+ $term_class_objects[$taxonomy] = $terms;
835
  }
836
  }
837
+
838
+ return $term_class_objects;
 
 
 
839
  }
840
 
841
  /**
880
  * @return array
881
  */
882
  function get_tags() {
883
+ return $this->get_terms('post_tag');
884
  }
885
 
886
  /**
1339
  * Get the terms associated with the post
1340
  * This goes across all taxonomies by default
1341
  * @api
1342
+ * @param string|array $tax What taxonom(y|ies) to pull from. Defaults to all registered taxonomies for the post type. You can use custom ones, or built-in WordPress taxonomies (category, tag). Timber plays nice and figures out that tag/tags/post_tag are all the same (and categories/category), for custom taxonomies you're on your own.
1343
  * @param bool $merge Should the resulting array be one big one (true)? Or should it be an array of sub-arrays for each taxonomy (false)?
1344
  * @return array
1345
  */
lib/timber-site.php CHANGED
@@ -22,216 +22,238 @@ class TimberSite extends TimberCore implements TimberCoreInterface {
22
  * @api
23
  * @var string the admin email address set in the WP admin panel
24
  */
25
- public $admin_email;
26
- public $blogname;
27
- /**
28
- * @api
29
- * @var string
30
- */
31
- public $charset;
32
-
33
- /**
34
- * @api
35
- * @var string
36
- */
37
- public $description;
38
- /**
39
- * @api
40
- * @var int the ID of a site in multisite
41
- */
42
- public $id;
43
- /**
44
- * @api
45
- * @var string the language setting ex: en-US
46
- */
47
- public $language;
48
- /**
49
- * @api
50
- * @var string of language attributes for usage in the <html> tag
51
- */
52
- public $language_attributes;
53
- /**
54
- * @api
55
- * @var bool true if multisite, false if plain ole' WordPress
56
- */
57
- public $multisite;
58
-
59
- /**
60
- * @api
61
- * @var string
62
- */
63
- public $name;
64
-
65
- /** @api
66
  * @var string for people who like trackback spam
67
- */
68
- public $pingback_url;
69
- public $siteurl;
70
- /**
71
- * @api
72
- * @var [TimberTheme](#TimberTheme)
73
- */
74
- public $theme;
75
- /**
76
- * @api
77
- * @var string
78
- */
79
- public $title;
80
- public $url;
81
-
82
- /**
83
- * Constructs a TimberSite object
84
- * @example
85
- * ```php
86
- * //multisite setup
87
- * $site = new TimberSite(1);
88
- * $site_two = new TimberSite("My Cool Site");
89
- * //non-multisite
90
- * $site = new TimberSite();
91
- * ```
92
- * @param string|int $site_name_or_id
93
- */
94
- function __construct( $site_name_or_id = null ) {
95
- if ( is_multisite() ) {
96
- $this->init_with_multisite( $site_name_or_id );
97
- } else {
98
- $this->init();
99
- }
100
- }
101
-
102
- /**
103
- * @internal
104
- * @param string|int $site_name_or_id
105
- */
106
- protected function init_with_multisite( $site_name_or_id ) {
107
- if ( $site_name_or_id === null ) {
108
- //this is necessary for some reason, otherwise returns 1 all the time
109
- if ( is_multisite() ) {
110
- restore_current_blog();
111
- $site_name_or_id = get_current_blog_id();
112
- }
113
- }
114
- $info = get_blog_details( $site_name_or_id );
115
- $this->import( $info );
116
- $this->ID = $info->blog_id;
117
- $this->id = $this->ID;
118
- $this->name = $this->blogname;
119
- $this->title = $this->blogname;
120
- $this->url = $this->siteurl;
121
- $theme_slug = get_blog_option( $info->blog_id, 'stylesheet' );
122
- $this->theme = new TimberTheme( $theme_slug );
123
- $this->language = get_bloginfo( 'language' );
124
- $this->charset = get_bloginfo( 'charset' );
125
- $this->pingback_url = get_bloginfo( 'pingback_url' );
126
- $this->language_attributes = TimberHelper::function_wrapper( 'language_attributes' );
127
- $this->description = get_blog_option( $info->blog_id, 'blogdescription' );
128
- $this->multisite = true;
129
- $this->admin_email = get_blog_option( $info->blog_id, 'admin_email' );
130
- }
131
-
132
- /**
133
- * @internal
134
- */
135
- protected function init() {
136
- $this->admin_email = get_bloginfo( 'admin_email' );
137
- $this->name = get_bloginfo( 'name' );
138
- $this->title = $this->name;
139
- $this->description = get_bloginfo( 'description' );
140
- $this->url = get_bloginfo( 'url' );
141
- $this->language = get_bloginfo( 'language' );
142
- $this->charset = get_bloginfo( 'charset' );
143
- $this->pingback_url = get_bloginfo( 'pingback_url' );
144
- $this->theme = new TimberTheme();
145
- $this->language_attributes = TimberHelper::function_wrapper( 'language_attributes' );
146
- $this->multisite = false;
147
- }
148
-
149
- /**
150
- *
151
- *
152
- * @param string $field
153
- * @return mixed
154
- */
155
- function __get( $field ) {
156
- if ( !isset( $this->$field ) ) {
157
- if ( is_multisite() ) {
158
- $this->$field = get_blog_option( $this->ID, $field );
159
- } else {
160
- $this->$field = get_option( $field );
161
- }
162
- }
163
- return $this->$field;
164
- }
165
-
166
- /**
167
- * @deprecated 0.21.9
168
- * @internal
169
- * @return string
170
- */
171
- function get_link() {
172
- return $this->link();
173
- }
174
-
175
- /**
176
- * @deprecated 0.21.9
177
- * @internal
178
- * @return string
179
- */
180
- function get_url() {
181
- return $this->get_link();
182
- }
183
-
184
- /**
185
- * Returns the link to the site's home.
186
- * @example
187
- * ```twig
188
- * <a href="{{ site.link }}" title="Home">
189
- * <img src="/wp-content/uploads/logo.png" alt="Logo for some stupid thing" />
190
- * </a>
191
- * ```
192
- * ```html
193
- * <a href="http://example.org" title="Home">
194
- * <img src="/wp-content/uploads/logo.png" alt="Logo for some stupid thing" />
195
- * </a>
196
- * ```
197
- * @api
198
- * @return string
199
- */
200
- public function link() {
201
- return $this->url;
202
- }
203
-
204
- /**
205
- * @ignore
206
- */
207
- public function meta( $field ) {
208
- return $this->__get( $field );
209
- }
210
-
211
- /**
212
- *
213
- * @ignore
214
- * @param string $key
215
- * @param mixed $value
216
- */
217
- public function update( $key, $value ) {
218
- $value = apply_filters( 'timber_site_set_meta', $value, $key, $this->ID, $this );
219
- if ( is_multisite() ) {
220
- update_blog_option( $this->ID, $key, $value );
221
- } else {
222
- update_option( $key, $value );
223
- }
224
- $this->$key = $value;
225
- }
226
-
227
- /**
228
- *
229
- * @api
230
- * @see TimberSite::link
231
- * @return string
232
- */
233
- function url() {
234
- return $this->get_link();
235
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
 
237
  }
22
  * @api
23
  * @var string the admin email address set in the WP admin panel
24
  */
25
+ public $admin_email;
26
+ public $blogname;
27
+ /**
28
+ * @api
29
+ * @var string
30
+ */
31
+ public $charset;
32
+
33
+ /**
34
+ * @api
35
+ * @var string
36
+ */
37
+ public $description;
38
+ /**
39
+ * @api
40
+ * @var int the ID of a site in multisite
41
+ */
42
+ public $id;
43
+ /**
44
+ * @api
45
+ * @var string the language setting ex: en-US
46
+ */
47
+ public $language;
48
+ /**
49
+ * @api
50
+ * @var string of language attributes for usage in the <html> tag
51
+ */
52
+ public $language_attributes;
53
+ /**
54
+ * @api
55
+ * @var bool true if multisite, false if plain ole' WordPress
56
+ */
57
+ public $multisite;
58
+
59
+ /**
60
+ * @api
61
+ * @var string
62
+ */
63
+ public $name;
64
+
65
+ /** @api
66
  * @var string for people who like trackback spam
67
+ */
68
+ public $pingback_url;
69
+ public $siteurl;
70
+ /**
71
+ * @api
72
+ * @var [TimberTheme](#TimberTheme)
73
+ */
74
+ public $theme;
75
+ /**
76
+ * @api
77
+ * @var string
78
+ */
79
+ public $title;
80
+ public $url;
81
+
82
+ /**
83
+ * @api
84
+ * @var string
85
+ */
86
+
87
+ public $rdf;
88
+ public $rss;
89
+ public $rss2;
90
+ public $atom;
91
+
92
+ /**
93
+ * Constructs a TimberSite object
94
+ * @example
95
+ * ```php
96
+ * //multisite setup
97
+ * $site = new TimberSite(1);
98
+ * $site_two = new TimberSite("My Cool Site");
99
+ * //non-multisite
100
+ * $site = new TimberSite();
101
+ * ```
102
+ * @param string|int $site_name_or_id
103
+ */
104
+ function __construct( $site_name_or_id = null ) {
105
+ $this->init();
106
+ if ( is_multisite() ) {
107
+ $this->init_as_multisite( $site_name_or_id );
108
+ } else {
109
+ $this->init_as_singlesite();
110
+ }
111
+ }
112
+
113
+ /**
114
+ * @internal
115
+ * @param string|int $site_name_or_id
116
+ */
117
+ protected function init_as_multisite( $site_name_or_id ) {
118
+ if ( $site_name_or_id === null ) {
119
+ //this is necessary for some reason, otherwise returns 1 all the time
120
+ if ( is_multisite() ) {
121
+ restore_current_blog();
122
+ $site_name_or_id = get_current_blog_id();
123
+ }
124
+ }
125
+ $info = get_blog_details( $site_name_or_id );
126
+ $this->import( $info );
127
+ $this->ID = $info->blog_id;
128
+ $this->id = $this->ID;
129
+ $this->name = $this->blogname;
130
+ $this->title = $this->blogname;
131
+ $this->url = $this->siteurl;
132
+ $theme_slug = get_blog_option( $info->blog_id, 'stylesheet' );
133
+ $this->theme = new TimberTheme( $theme_slug );
134
+ $this->description = get_blog_option( $info->blog_id, 'blogdescription' );
135
+ $this->admin_email = get_blog_option( $info->blog_id, 'admin_email' );
136
+ $this->multisite = true;
137
+ }
138
+
139
+ /**
140
+ * Executed for single-blog sites
141
+ * @internal
142
+ */
143
+ protected function init_as_singlesite() {
144
+ $this->admin_email = get_bloginfo( 'admin_email' );
145
+ $this->name = get_bloginfo( 'name' );
146
+ $this->title = $this->name;
147
+ $this->description = get_bloginfo( 'description' );
148
+ $this->url = get_bloginfo( 'url' );
149
+ $this->theme = new TimberTheme();
150
+ $this->language_attributes = TimberHelper::function_wrapper( 'language_attributes' );
151
+ $this->multisite = false;
152
+ }
153
+
154
+ /**
155
+ * Executed for all types of sites: both multisite and "regular"
156
+ * @internal
157
+ */
158
+ protected function init() {
159
+ $this->rdf = get_bloginfo( 'rdf_url' );
160
+ $this->rss = get_bloginfo( 'rss_url' );
161
+ $this->rss2 = get_bloginfo( 'rss2_url' );
162
+ $this->atom = get_bloginfo( 'atom_url' );
163
+ $this->language = get_bloginfo( 'language' );
164
+ $this->charset = get_bloginfo( 'charset' );
165
+ $this->pingback = get_bloginfo( 'pingback_url' );
166
+ $this->language_attributes = TimberHelper::function_wrapper( 'language_attributes' );
167
+ /* deprecated benath this comment */
168
+ $this->pingback_url = get_bloginfo( 'pingback_url' );
169
+ }
170
+
171
+ /**
172
+ *
173
+ *
174
+ * @param string $field
175
+ * @return mixed
176
+ */
177
+ function __get( $field ) {
178
+ if ( !isset( $this->$field ) ) {
179
+ if ( is_multisite() ) {
180
+ $this->$field = get_blog_option( $this->ID, $field );
181
+ } else {
182
+ $this->$field = get_option( $field );
183
+ }
184
+ }
185
+ return $this->$field;
186
+ }
187
+
188
+ /**
189
+ * @deprecated 0.21.9
190
+ * @internal
191
+ * @return string
192
+ */
193
+ function get_link() {
194
+ return $this->link();
195
+ }
196
+
197
+ /**
198
+ * @deprecated 0.21.9
199
+ * @internal
200
+ * @return string
201
+ */
202
+ function get_url() {
203
+ return $this->get_link();
204
+ }
205
+
206
+ /**
207
+ * Returns the link to the site's home.
208
+ * @example
209
+ * ```twig
210
+ * <a href="{{ site.link }}" title="Home">
211
+ * <img src="/wp-content/uploads/logo.png" alt="Logo for some stupid thing" />
212
+ * </a>
213
+ * ```
214
+ * ```html
215
+ * <a href="http://example.org" title="Home">
216
+ * <img src="/wp-content/uploads/logo.png" alt="Logo for some stupid thing" />
217
+ * </a>
218
+ * ```
219
+ * @api
220
+ * @return string
221
+ */
222
+ public function link() {
223
+ return $this->url;
224
+ }
225
+
226
+ /**
227
+ * @ignore
228
+ */
229
+ public function meta( $field ) {
230
+ return $this->__get( $field );
231
+ }
232
+
233
+ /**
234
+ *
235
+ * @ignore
236
+ * @param string $key
237
+ * @param mixed $value
238
+ */
239
+ public function update( $key, $value ) {
240
+ $value = apply_filters( 'timber_site_set_meta', $value, $key, $this->ID, $this );
241
+ if ( is_multisite() ) {
242
+ update_blog_option( $this->ID, $key, $value );
243
+ } else {
244
+ update_option( $key, $value );
245
+ }
246
+ $this->$key = $value;
247
+ }
248
+
249
+ /**
250
+ *
251
+ * @api
252
+ * @see TimberSite::link
253
+ * @return string
254
+ */
255
+ function url() {
256
+ return $this->get_link();
257
+ }
258
 
259
  }
lib/timber-term-getter.php CHANGED
@@ -179,4 +179,4 @@ class TimberTermGetter
179
  return $taxs;
180
  }
181
 
182
- }
179
  return $taxs;
180
  }
181
 
182
+ }
lib/timber-term.php CHANGED
@@ -71,6 +71,15 @@ class TimberTerm extends TimberCore implements TimberCoreInterface {
71
  return $this->name;
72
  }
73
 
 
 
 
 
 
 
 
 
 
74
 
75
 
76
  /* Setup
71
  return $this->name;
72
  }
73
 
74
+ /**
75
+ * @param $tid
76
+ * @param $taxonomy
77
+ *
78
+ * @return static
79
+ */
80
+ public static function from( $tid, $taxonomy ) {
81
+ return new static($tid, $taxonomy);
82
+ }
83
 
84
 
85
  /* Setup
lib/timber-twig.php CHANGED
@@ -266,7 +266,7 @@ class TimberTwig {
266
 
267
  if ( $date instanceof DateTime ) {
268
  $timestamp = $date->getTimestamp();
269
- } else if (is_numeric( $date ) ) {
270
  $timestamp = intval( $date );
271
  } else {
272
  $timestamp = strtotime( $date );
266
 
267
  if ( $date instanceof DateTime ) {
268
  $timestamp = $date->getTimestamp();
269
+ } else if (is_numeric( $date ) && strtotime( $date ) === false ) {
270
  $timestamp = intval( $date );
271
  } else {
272
  $timestamp = strtotime( $date );
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: jarednova
3
  Tags: template engine, templates, twig
4
  Requires at least: 3.7
5
- Stable tag: 0.22.0
6
  Tested up to: 4.2.3
7
  PHP version: 5.3.0 or greater
8
  License: GPLv2 or later
@@ -41,11 +41,16 @@ Timber is great for any WordPress developer who cares about writing good, mainta
41
 
42
  == Changelog ==
43
 
 
 
 
 
 
44
  = 0.22.0 =
45
- * Added fetch method to Timber (thanks @xaivars and @erik-landvall)
46
  * Added a total to the pagination data array (thanks @lggorman)
47
  * Threaded comments get some love! (thanks @josephbergdoll)
48
- * A fix to date parsing when handling numeric timestamps (thanks @xaivars)
49
 
50
  = 0.21.10 =
51
  * Removed deprecated twitterify function
2
  Contributors: jarednova
3
  Tags: template engine, templates, twig
4
  Requires at least: 3.7
5
+ Stable tag: 0.22.1
6
  Tested up to: 4.2.3
7
  PHP version: 5.3.0 or greater
8
  License: GPLv2 or later
41
 
42
  == Changelog ==
43
 
44
+ = 0.22.1 =
45
+ * Added better support for [post.get_terms](https://github.com/jarednova/timber/pull/737) (thanks @aaemnnosttv)
46
+ * Fix for issue with ACF date field (thanks @rpkoller)
47
+ * Fix for resizing jpEgs (thanks @eaton)
48
+
49
  = 0.22.0 =
50
+ * Added fetch method to Timber (thanks @xavivars and @erik-landvall)
51
  * Added a total to the pagination data array (thanks @lggorman)
52
  * Threaded comments get some love! (thanks @josephbergdoll)
53
+ * A fix to date parsing when handling numeric timestamps (thanks @xavivars)
54
 
55
  = 0.21.10 =
56
  * Removed deprecated twitterify function
timber.php CHANGED
@@ -1,19 +1,19 @@
1
  <?php
2
  /*
3
  Plugin Name: Timber
 
4
  Plugin URI: http://timber.upstatement.com
5
- Description: The WordPress Timber Library allows you to write themes using the power Twig templates
6
  Author: Jared Novack + Upstatement
7
- Version: 0.22.0
8
  Author URI: http://upstatement.com/
9
  */
10
 
11
  global $wp_version;
12
  global $timber;
13
 
14
- // we look for Composer files first in the plugins dir
15
- // then in the wp-content dir (site install)
16
- // and finally in the current themes directories
17
  if ( file_exists( $composer_autoload = __DIR__ . '/vendor/autoload.php' ) /* check in self */
18
  || file_exists( $composer_autoload = WP_CONTENT_DIR.'/vendor/autoload.php') /* check in wp-content */
19
  || file_exists( $composer_autoload = plugin_dir_path( __FILE__ ).'vendor/autoload.php') /* check in plugin directory */
@@ -26,18 +26,21 @@ if ( file_exists( $composer_autoload = __DIR__ . '/vendor/autoload.php' ) /* c
26
  $timber = new Timber();
27
  Timber::$dirname = 'views';
28
 
29
- /** Usage:
 
30
  *
 
 
 
31
  * $posts = Timber::get_posts();
32
  * $posts = Timber::get_posts('post_type = article')
33
- * $posts = Timber::get_posts(array('post_type' => 'article', 'category_name' => 'sports')); // uses wp_query format
34
  * $posts = Timber::get_posts(array(23,24,35,67), 'InkwellArticle');
35
  *
36
  * $context = Timber::get_context(); // returns wp favorites!
37
  * $context['posts'] = $posts;
38
  * Timber::render('index.twig', $context);
39
  */
40
-
41
  class Timber {
42
 
43
  public static $locations;
@@ -80,10 +83,12 @@ class Timber {
80
  TimberIntegrations::init();
81
  }
82
 
83
- /* Post Retrieval
84
  ================================ */
85
 
86
  /**
 
 
87
  * @param mixed $query
88
  * @param string $PostClass
89
  * @return array|bool|null
@@ -93,6 +98,8 @@ class Timber {
93
  }
94
 
95
  /**
 
 
96
  * @param mixed $query
97
  * @param string $PostClass
98
  * @return array|bool|null
@@ -102,6 +109,8 @@ class Timber {
102
  }
103
 
104
  /**
 
 
105
  * @param mixed $query
106
  * @param string $PostClass
107
  * @return array|bool|null
@@ -111,6 +120,8 @@ class Timber {
111
  }
112
 
113
  /**
 
 
114
  * @param mixed $query
115
  * @param string $PostClass
116
  * @return array|bool|null
@@ -120,6 +131,8 @@ class Timber {
120
  }
121
 
122
  /**
 
 
123
  * @param array|string $query
124
  * @return array
125
  * @deprecated since 0.20.0
@@ -129,6 +142,8 @@ class Timber {
129
  }
130
 
131
  /**
 
 
132
  * @param string $PostClass
133
  * @return array
134
  * @deprecated since 0.20.0
@@ -138,6 +153,8 @@ class Timber {
138
  }
139
 
140
  /**
 
 
141
  * @param string $slug
142
  * @param string $PostClass
143
  * @return array
@@ -148,6 +165,8 @@ class Timber {
148
  }
149
 
150
  /**
 
 
151
  * @param array $query
152
  * @param string $PostClass
153
  * @return array
@@ -158,6 +177,8 @@ class Timber {
158
  }
159
 
160
  /**
 
 
161
  * @param array $query
162
  * @param string $PostClass
163
  * @return array|null
@@ -168,6 +189,8 @@ class Timber {
168
  }
169
 
170
  /**
 
 
171
  * @param unknown $query
172
  * @return int
173
  * @deprecated since 0.20.0
@@ -180,6 +203,8 @@ class Timber {
180
  }
181
 
182
  /**
 
 
183
  * @return bool
184
  * @deprecated since 0.20.0
185
  */
@@ -191,6 +216,8 @@ class Timber {
191
  ================================ */
192
 
193
  /**
 
 
194
  * @param string|array $args
195
  * @param array $maybe_args
196
  * @param string $TermClass
@@ -204,6 +231,8 @@ class Timber {
204
  ================================ */
205
 
206
  /**
 
 
207
  * @param array|bool $blog_ids
208
  * @return array
209
  */
@@ -224,6 +253,8 @@ class Timber {
224
  ================================ */
225
 
226
  /**
 
 
227
  * @return array
228
  */
229
  public static function get_context() {
@@ -257,6 +288,8 @@ class Timber {
257
  }
258
 
259
  /**
 
 
260
  * @param array $filenames
261
  * @param array $data
262
  * @param bool $expires
@@ -289,8 +322,10 @@ class Timber {
289
  }
290
 
291
  /**
292
- * @param string $string a string with twig variables
293
- * @param array $data an array with data in it
 
 
294
  * @return bool|string
295
  */
296
  public static function compile_string( $string, $data = array() ) {
@@ -304,6 +339,8 @@ class Timber {
304
  }
305
 
306
  /**
 
 
307
  * @param array $filenames
308
  * @param array $data
309
  * @param bool $expires
@@ -323,6 +360,8 @@ class Timber {
323
  }
324
 
325
  /**
 
 
326
  * @param array $filenames
327
  * @param array $data
328
  * @param bool $expires
@@ -336,8 +375,10 @@ class Timber {
336
  }
337
 
338
  /**
339
- * @param string $string a string with twig variables
340
- * @param array $data an array with data in it
 
 
341
  * @return bool|string
342
  */
343
  public static function render_string( $string, $data = array() ) {
@@ -351,6 +392,8 @@ class Timber {
351
  ================================ */
352
 
353
  /**
 
 
354
  * @param string $sidebar
355
  * @param array $data
356
  * @return bool|string
@@ -366,6 +409,8 @@ class Timber {
366
  }
367
 
368
  /**
 
 
369
  * @param string $sidebar
370
  * @param array $data
371
  * @return string
@@ -395,6 +440,8 @@ class Timber {
395
  ================================ */
396
 
397
  /**
 
 
398
  * @param int $widget_id
399
  * @return TimberFunctionWrapper
400
  */
@@ -407,6 +454,8 @@ class Timber {
407
  ================================ */
408
 
409
  /**
 
 
410
  * @param string $route
411
  * @param callable $callback
412
  * @param array $args
@@ -427,6 +476,8 @@ class Timber {
427
  }
428
 
429
  /**
 
 
430
  * @deprecated since 0.20.0
431
  */
432
  public static function load_template( $template, $query = false, $status_code = 200, $tparams = false ) {
@@ -434,6 +485,8 @@ class Timber {
434
  }
435
 
436
  /**
 
 
437
  * @deprecated since 0.20.2
438
  */
439
  public static function load_view( $template, $query = false, $status_code = 200, $tparams = false ) {
@@ -445,6 +498,8 @@ class Timber {
445
  ================================ */
446
 
447
  /**
 
 
448
  * @param array $prefs
449
  * @return array mixed
450
  */
@@ -497,6 +552,8 @@ class Timber {
497
  ================================ */
498
 
499
  /**
 
 
500
  * @param int $offset
501
  * @return string
502
  * @deprecated since 0.20.0
@@ -507,6 +564,8 @@ class Timber {
507
  }
508
 
509
  /**
 
 
510
  * @return boolean|string
511
  */
512
  public static function get_calling_script_dir( $offset = 0 ) {
@@ -520,6 +579,8 @@ class Timber {
520
  }
521
 
522
  /**
 
 
523
  * @param int $offset
524
  * @return string|null
525
  * @deprecated since 0.20.0
@@ -542,6 +603,8 @@ class Timber {
542
  }
543
 
544
  /**
 
 
545
  * @param string|array $args
546
  * @return bool
547
  * @deprecated since 0.20.0
1
  <?php
2
  /*
3
  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: 0.22.1
8
  Author URI: http://upstatement.com/
9
  */
10
 
11
  global $wp_version;
12
  global $timber;
13
 
14
+ // we look for Composer files first in the plugins dir.
15
+ // then in the wp-content dir (site install).
16
+ // and finally in the current themes directories.
17
  if ( file_exists( $composer_autoload = __DIR__ . '/vendor/autoload.php' ) /* check in self */
18
  || file_exists( $composer_autoload = WP_CONTENT_DIR.'/vendor/autoload.php') /* check in wp-content */
19
  || file_exists( $composer_autoload = plugin_dir_path( __FILE__ ).'vendor/autoload.php') /* check in plugin directory */
26
  $timber = new Timber();
27
  Timber::$dirname = 'views';
28
 
29
+ /**
30
+ * Timber Class.
31
  *
32
+ * Main class called Timber for this plugin.
33
+ *
34
+ * Usage:
35
  * $posts = Timber::get_posts();
36
  * $posts = Timber::get_posts('post_type = article')
37
+ * $posts = Timber::get_posts(array('post_type' => 'article', 'category_name' => 'sports')); // uses wp_query format.
38
  * $posts = Timber::get_posts(array(23,24,35,67), 'InkwellArticle');
39
  *
40
  * $context = Timber::get_context(); // returns wp favorites!
41
  * $context['posts'] = $posts;
42
  * Timber::render('index.twig', $context);
43
  */
 
44
  class Timber {
45
 
46
  public static $locations;
83
  TimberIntegrations::init();
84
  }
85
 
86
+ /* Post Retrieval Routine
87
  ================================ */
88
 
89
  /**
90
+ * Get post.
91
+ *
92
  * @param mixed $query
93
  * @param string $PostClass
94
  * @return array|bool|null
98
  }
99
 
100
  /**
101
+ * Get posts.
102
+ *
103
  * @param mixed $query
104
  * @param string $PostClass
105
  * @return array|bool|null
109
  }
110
 
111
  /**
112
+ * Query post.
113
+ *
114
  * @param mixed $query
115
  * @param string $PostClass
116
  * @return array|bool|null
120
  }
121
 
122
  /**
123
+ * Query posts.
124
+ *
125
  * @param mixed $query
126
  * @param string $PostClass
127
  * @return array|bool|null
131
  }
132
 
133
  /**
134
+ * Get pids.
135
+ *
136
  * @param array|string $query
137
  * @return array
138
  * @deprecated since 0.20.0
142
  }
143
 
144
  /**
145
+ * Get posts from loop.
146
+ *
147
  * @param string $PostClass
148
  * @return array
149
  * @deprecated since 0.20.0
153
  }
154
 
155
  /**
156
+ * Get posts from slug.
157
+ *
158
  * @param string $slug
159
  * @param string $PostClass
160
  * @return array
165
  }
166
 
167
  /**
168
+ * Get posts from WP_Query.
169
+ *
170
  * @param array $query
171
  * @param string $PostClass
172
  * @return array
177
  }
178
 
179
  /**
180
+ * Get posts from array of ids.
181
+ *
182
  * @param array $query
183
  * @param string $PostClass
184
  * @return array|null
189
  }
190
 
191
  /**
192
+ * Get pid.
193
+ *
194
  * @param unknown $query
195
  * @return int
196
  * @deprecated since 0.20.0
203
  }
204
 
205
  /**
206
+ * WP_Query has posts.
207
+ *
208
  * @return bool
209
  * @deprecated since 0.20.0
210
  */
216
  ================================ */
217
 
218
  /**
219
+ * Get terms.
220
+ *
221
  * @param string|array $args
222
  * @param array $maybe_args
223
  * @param string $TermClass
231
  ================================ */
232
 
233
  /**
234
+ * Get sites.
235
+ *
236
  * @param array|bool $blog_ids
237
  * @return array
238
  */
253
  ================================ */
254
 
255
  /**
256
+ * Get context.
257
+ *
258
  * @return array
259
  */
260
  public static function get_context() {
288
  }
289
 
290
  /**
291
+ * Compile function.
292
+ *
293
  * @param array $filenames
294
  * @param array $data
295
  * @param bool $expires
322
  }
323
 
324
  /**
325
+ * Compile string.
326
+ *
327
+ * @param string $string a string with twig variables.
328
+ * @param array $data an array with data in it.
329
  * @return bool|string
330
  */
331
  public static function compile_string( $string, $data = array() ) {
339
  }
340
 
341
  /**
342
+ * Fetch function.
343
+ *
344
  * @param array $filenames
345
  * @param array $data
346
  * @param bool $expires
360
  }
361
 
362
  /**
363
+ * Render function.
364
+ *
365
  * @param array $filenames
366
  * @param array $data
367
  * @param bool $expires
375
  }
376
 
377
  /**
378
+ * Render string.
379
+ *
380
+ * @param string $string a string with twig variables.
381
+ * @param array $data an array with data in it.
382
  * @return bool|string
383
  */
384
  public static function render_string( $string, $data = array() ) {
392
  ================================ */
393
 
394
  /**
395
+ * Get sidebar.
396
+ *
397
  * @param string $sidebar
398
  * @param array $data
399
  * @return bool|string
409
  }
410
 
411
  /**
412
+ * Get sidebar from PHP
413
+ *
414
  * @param string $sidebar
415
  * @param array $data
416
  * @return string
440
  ================================ */
441
 
442
  /**
443
+ * Get widgets.
444
+ *
445
  * @param int $widget_id
446
  * @return TimberFunctionWrapper
447
  */
454
  ================================ */
455
 
456
  /**
457
+ * Add route.
458
+ *
459
  * @param string $route
460
  * @param callable $callback
461
  * @param array $args
476
  }
477
 
478
  /**
479
+ * Load template.
480
+ *
481
  * @deprecated since 0.20.0
482
  */
483
  public static function load_template( $template, $query = false, $status_code = 200, $tparams = false ) {
485
  }
486
 
487
  /**
488
+ * Load view.
489
+ *
490
  * @deprecated since 0.20.2
491
  */
492
  public static function load_view( $template, $query = false, $status_code = 200, $tparams = false ) {
498
  ================================ */
499
 
500
  /**
501
+ * Get pagination.
502
+ *
503
  * @param array $prefs
504
  * @return array mixed
505
  */
552
  ================================ */
553
 
554
  /**
555
+ * Get calling script path.
556
+ *
557
  * @param int $offset
558
  * @return string
559
  * @deprecated since 0.20.0
564
  }
565
 
566
  /**
567
+ * Get calling script dir.
568
+ *
569
  * @return boolean|string
570
  */
571
  public static function get_calling_script_dir( $offset = 0 ) {
579
  }
580
 
581
  /**
582
+ * Get calling script file.
583
+ *
584
  * @param int $offset
585
  * @return string|null
586
  * @deprecated since 0.20.0
603
  }
604
 
605
  /**
606
+ * Is post class or class map.
607
+ *
608
  * @param string|array $args
609
  * @return bool
610
  * @deprecated since 0.20.0
vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once __DIR__ . '/composer' . '/autoload_real.php';
6
 
7
- return ComposerAutoloaderInit68e9a33653fcf1bfe1a370e1f36812f3::getLoader();
4
 
5
  require_once __DIR__ . '/composer' . '/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInit0c8bebb789915cc09e196c0fd45125c4::getLoader();
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInit68e9a33653fcf1bfe1a370e1f36812f3
6
  {
7
  private static $loader;
8
 
@@ -19,9 +19,9 @@ class ComposerAutoloaderInit68e9a33653fcf1bfe1a370e1f36812f3
19
  return self::$loader;
20
  }
21
 
22
- spl_autoload_register(array('ComposerAutoloaderInit68e9a33653fcf1bfe1a370e1f36812f3', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
- spl_autoload_unregister(array('ComposerAutoloaderInit68e9a33653fcf1bfe1a370e1f36812f3', 'loadClassLoader'));
25
 
26
  $map = require __DIR__ . '/autoload_namespaces.php';
27
  foreach ($map as $namespace => $path) {
@@ -44,7 +44,7 @@ class ComposerAutoloaderInit68e9a33653fcf1bfe1a370e1f36812f3
44
  }
45
  }
46
 
47
- function composerRequire68e9a33653fcf1bfe1a370e1f36812f3($file)
48
  {
49
  require $file;
50
  }
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
+ class ComposerAutoloaderInit0c8bebb789915cc09e196c0fd45125c4
6
  {
7
  private static $loader;
8
 
19
  return self::$loader;
20
  }
21
 
22
+ spl_autoload_register(array('ComposerAutoloaderInit0c8bebb789915cc09e196c0fd45125c4', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
+ spl_autoload_unregister(array('ComposerAutoloaderInit0c8bebb789915cc09e196c0fd45125c4', 'loadClassLoader'));
25
 
26
  $map = require __DIR__ . '/autoload_namespaces.php';
27
  foreach ($map as $namespace => $path) {
44
  }
45
  }
46
 
47
+ function composerRequire0c8bebb789915cc09e196c0fd45125c4($file)
48
  {
49
  require $file;
50
  }