Timber - Version 0.16.0

Version Description

  • TimberTheme is now available in default context as .theme
  • Post meta now respects arrays (watch out for some possible compatiblity issues here)
  • Template loads now work for parent/child themes in Windows (thanks @matthewsoares)
  • Better method for removing 404 body class on manual redirects (thanks @mgmartel)
Download this release

Release Info

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

Code changes from version 0.15.5 to 0.16.0

Twig/AUTHORS CHANGED
File without changes
Twig/CHANGELOG CHANGED
File without changes
Twig/README.markdown CHANGED
File without changes
Twig/lib/Twig/Compiler.php CHANGED
File without changes
Twig/lib/Twig/Environment.php CHANGED
File without changes
Twig/lib/Twig/Error.php CHANGED
File without changes
Twig/lib/Twig/ExpressionParser.php CHANGED
File without changes
Twig/lib/Twig/Extension/Core.php CHANGED
File without changes
Twig/lib/Twig/Extension/StringLoader.php CHANGED
File without changes
Twig/lib/Twig/Lexer.php CHANGED
File without changes
Twig/lib/Twig/LexerInterface.php CHANGED
File without changes
Twig/lib/Twig/Loader/Array.php CHANGED
File without changes
Twig/lib/Twig/Loader/Chain.php CHANGED
File without changes
Twig/lib/Twig/Loader/Filesystem.php CHANGED
File without changes
Twig/lib/Twig/Node/Expression/Call.php CHANGED
File without changes
Twig/lib/Twig/Node/Expression/GetAttr.php CHANGED
File without changes
Twig/lib/Twig/Node/If.php CHANGED
File without changes
Twig/lib/Twig/NodeVisitor/Optimizer.php CHANGED
File without changes
Twig/lib/Twig/NodeVisitor/SafeAnalysis.php CHANGED
File without changes
Twig/lib/Twig/Parser.php CHANGED
File without changes
Twig/lib/Twig/ParserInterface.php CHANGED
File without changes
Twig/lib/Twig/Template.php CHANGED
File without changes
Twig/lib/Twig/Token.php CHANGED
File without changes
Twig/lib/Twig/TokenParserInterface.php CHANGED
File without changes
functions/integrations/wpcli-timber.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Timber_Command extends WP_CLI_Command{
4
+
5
+ /**
6
+ * Clears Twig's Cache
7
+ *
8
+ * ## EXAMPLES
9
+ *
10
+ * wp clear_cache
11
+ *
12
+ * @synopsis <nothing>
13
+ */
14
+ function clear_cache(){
15
+ $files = glob('../../twig-cache/*');
16
+ foreach($files as $file){
17
+ if (is_file($file)) {
18
+ unlink($file);
19
+ }
20
+ }
21
+ }
22
+
23
+ /**
24
+ * ## EXAMPLES
25
+ * wp timber poop
26
+ */
27
+
28
+ function poop(){
29
+ WP_CLI::success('HEllo!!! poopy pants');
30
+ }
31
+
32
+ }
33
+
34
+ WP_CLI::add_command( 'timber', 'Timber_Command' );
functions/timber-helper.php CHANGED
@@ -420,8 +420,9 @@ class TimberHelper {
420
  if ( $prev_next && $current && 1 < $current ) :
421
  $link = str_replace('%_%', 2 == $current ? '' : $format, $base);
422
  $link = str_replace('%#%', $current - 1, $link);
423
- if ( $add_args )
424
  $link = add_query_arg( $add_args, $link );
 
425
  $link .= $add_fragment;
426
  $page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $prev_text . '</a>';
427
  endif;
@@ -435,8 +436,10 @@ class TimberHelper {
435
  if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
436
  $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
437
  $link = str_replace('%#%', $n, $link);
438
- if ( $add_args )
439
  $link = add_query_arg( $add_args, $link );
 
 
440
  $link = trailingslashit($link).ltrim($add_fragment, '/');
441
  //$page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>$n_display</a>";
442
  $page_links[] = array('class' => 'page-number', 'link' => esc_url( apply_filters( 'paginate_links', $link ) ), 'title' => $n_display);
420
  if ( $prev_next && $current && 1 < $current ) :
421
  $link = str_replace('%_%', 2 == $current ? '' : $format, $base);
422
  $link = str_replace('%#%', $current - 1, $link);
423
+ if ( $add_args ){
424
  $link = add_query_arg( $add_args, $link );
425
+ }
426
  $link .= $add_fragment;
427
  $page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $prev_text . '</a>';
428
  endif;
436
  if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
437
  $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
438
  $link = str_replace('%#%', $n, $link);
439
+ if ( $add_args ) {
440
  $link = add_query_arg( $add_args, $link );
441
+ }
442
+
443
  $link = trailingslashit($link).ltrim($add_fragment, '/');
444
  //$page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>$n_display</a>";
445
  $page_links[] = array('class' => 'page-number', 'link' => esc_url( apply_filters( 'paginate_links', $link ) ), 'title' => $n_display);
functions/timber-loader.php CHANGED
@@ -88,6 +88,10 @@ class TimberLoader {
88
  $theme_locs = array();
89
  $child_loc = get_stylesheet_directory();
90
  $parent_loc = get_template_directory();
 
 
 
 
91
  $theme_locs[] = $child_loc;
92
  $theme_locs[] = trailingslashit($child_loc) . trailingslashit(Timber::$dirname);
93
  if ($child_loc != $parent_loc) {
88
  $theme_locs = array();
89
  $child_loc = get_stylesheet_directory();
90
  $parent_loc = get_template_directory();
91
+ if (DIRECTORY_SEPARATOR == '\\') {
92
+ $child_loc = str_replace('/', '\\', $child_loc);
93
+ $parent_loc = str_replace('/', '\\', $parent_loc);
94
+ }
95
  $theme_locs[] = $child_loc;
96
  $theme_locs[] = trailingslashit($child_loc) . trailingslashit(Timber::$dirname);
97
  if ($child_loc != $parent_loc) {
functions/timber-post.php CHANGED
@@ -196,8 +196,10 @@ class TimberPost extends TimberCore {
196
  return;
197
  }
198
  foreach ($customs as $key => $value) {
199
- $v = $value[0];
200
- $customs[$key] = maybe_unserialize($v);
 
 
201
  }
202
  $customs = apply_filters('timber_post_get_meta', $customs, $pid, $this);
203
  return $customs;
@@ -451,7 +453,10 @@ class TimberPost extends TimberCore {
451
  public function get_field($field_name) {
452
  $value = apply_filters('timber_post_get_meta_field_pre', null, $this->ID, $field_name, $this);
453
  if ($value === null){
454
- $value = get_post_meta($this->ID, $field_name, true);
 
 
 
455
  }
456
  $value = apply_filters('timber_post_get_meta_field', $value, $this->ID, $field_name, $this);
457
  return $value;
196
  return;
197
  }
198
  foreach ($customs as $key => $value) {
199
+ if (is_array($value) && count($value) == 1 && isset($value[0])){
200
+ $value = $value[0];
201
+ }
202
+ $customs[$key] = maybe_unserialize($value);
203
  }
204
  $customs = apply_filters('timber_post_get_meta', $customs, $pid, $this);
205
  return $customs;
453
  public function get_field($field_name) {
454
  $value = apply_filters('timber_post_get_meta_field_pre', null, $this->ID, $field_name, $this);
455
  if ($value === null){
456
+ $value = get_post_meta($this->ID, $field_name);
457
+ if (is_array($value) && count($value == 1)){
458
+ $value = $value[0];
459
+ }
460
  }
461
  $value = apply_filters('timber_post_get_meta_field', $value, $this->ID, $field_name, $this);
462
  return $value;
functions/timber-theme.php CHANGED
@@ -3,7 +3,8 @@
3
  class TimberTheme extends TimberCore {
4
 
5
  function __construct($slug = null){
6
- $this->init($slug);
 
7
  }
8
 
9
  function init($slug = null){
@@ -12,7 +13,12 @@
12
  $ss = $data->get_stylesheet();
13
  $this->slug = $ss;
14
  $this->path = '/'.str_replace(ABSPATH, '', get_stylesheet_directory());
 
15
  $this->parent_slug = $data->get('Template');
 
 
 
 
16
  if ($this->parent_slug && $this->parent_slug != $this->slug){
17
  $this->parent = new TimberTheme($this->parent_slug);
18
  }
3
  class TimberTheme extends TimberCore {
4
 
5
  function __construct($slug = null){
6
+ $this->
7
+ init($slug);
8
  }
9
 
10
  function init($slug = null){
13
  $ss = $data->get_stylesheet();
14
  $this->slug = $ss;
15
  $this->path = '/'.str_replace(ABSPATH, '', get_stylesheet_directory());
16
+ $this->uri = get_stylesheet_directory_uri();
17
  $this->parent_slug = $data->get('Template');
18
+ if (!$this->parent_slug){
19
+ $this->path = '/'.str_replace(ABSPATH, '', get_template_directory());
20
+ $this->uri = get_template_directory_uri();
21
+ }
22
  if ($this->parent_slug && $this->parent_slug != $this->slug){
23
  $this->parent = new TimberTheme($this->parent_slug);
24
  }
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: jarednova
3
  Tags: template engine, templates, twig
4
  Requires at least: 3.5
5
- Stable tag: 0.15.5
6
  Tested up to: 3.7.1
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
  = 0.15.5 =
45
  * Post formats: {{post.format}} !
46
 
2
  Contributors: jarednova
3
  Tags: template engine, templates, twig
4
  Requires at least: 3.5
5
+ Stable tag: 0.16.0
6
  Tested up to: 3.7.1
7
  PHP version: 5.3.0 or greater
8
  License: GPLv2 or later
41
 
42
  == Changelog ==
43
 
44
+ = 0.16.0 =
45
+ * TimberTheme is now available in default context as .theme
46
+ * Post meta now respects arrays (watch out for some possible compatiblity issues here)
47
+ * Template loads now work for parent/child themes in Windows (thanks @matthewsoares)
48
+ * Better method for removing 404 body class on manual redirects (thanks @mgmartel)
49
+
50
  = 0.15.5 =
51
  * Post formats: {{post.format}} !
52
 
timber-starter-theme/views/page.twig CHANGED
@@ -5,10 +5,10 @@
5
  <div class="content-wrapper">
6
  <article class="post-type-{{post.post_type}}" id="post-{{post.ID}}">
7
  <section class="article-content">
8
- <h1 class="article-h1">{{post.post_title}}</h1>
9
-
10
  <div class="article-body">
11
- {{post.get_content}}
12
  </div>
13
  </section>
14
 
5
  <div class="content-wrapper">
6
  <article class="post-type-{{post.post_type}}" id="post-{{post.ID}}">
7
  <section class="article-content">
8
+ <h1 class="article-h1">{{post.title}}</h1>
9
+
10
  <div class="article-body">
11
+ {{post.content}}
12
  </div>
13
  </section>
14
 
timber-starter-theme/views/single.twig CHANGED
@@ -5,14 +5,14 @@
5
  <div class="content-wrapper">
6
  <article class="post-type-{{post.post_type}}" id="post-{{post.ID}}">
7
  <section class="article-content">
8
- <h1 class="article-h1">{{post.post_title}}</h1>
9
 
10
  <p class="blog-author">
11
- <span>By</span><a href="{{post.author.get_path}}"> {{ post.author.name }} </a><span>&bull;</span> {{ post.display_date }}
12
  </p>
13
 
14
  <div class="article-body">
15
- {{post.get_content}}
16
  </div>
17
  </section>
18
 
@@ -23,10 +23,10 @@
23
  </div>
24
  <div class="responses">
25
 
26
- {% for cmt in post.get_comments() %}
27
- {% include "comment.twig" with {comment:cmt} %}
28
- {% endfor %}
29
- </div>
30
 
31
  </section>
32
 
5
  <div class="content-wrapper">
6
  <article class="post-type-{{post.post_type}}" id="post-{{post.ID}}">
7
  <section class="article-content">
8
+ <h1 class="article-h1">{{post.title}}</h1>
9
 
10
  <p class="blog-author">
11
+ <span>By</span><a href="{{post.author.path}}"> {{ post.author.name }} </a><span>&bull;</span> {{ post.display_date }}
12
  </p>
13
 
14
  <div class="article-body">
15
+ {{post.content}}
16
  </div>
17
  </section>
18
 
23
  </div>
24
  <div class="responses">
25
 
26
+ {% for cmt in post.get_comments() %}
27
+ {% include "comment.twig" with {comment:cmt} %}
28
+ {% endfor %}
29
+ </div>
30
 
31
  </section>
32
 
timber-starter-theme/views/tease-post.twig CHANGED
@@ -1,9 +1,9 @@
1
  {% extends "tease.twig" %}
2
  {% block content %}
3
- <h2 class="h2"><a href="{{post.permalink}}">{{post.title}}</a></h2>
4
  <p>{{post.get_preview(25)}}</p>
5
 
6
- {% if post.get_thumbnail %}
7
- <img src="{{post.get_thumbnail.get_url}}" />
8
  {% endif %}
9
  {% endblock %}
1
  {% extends "tease.twig" %}
2
  {% block content %}
3
+ <h2 class="h2"><a href="{{post.link}}">{{post.title}}</a></h2>
4
  <p>{{post.get_preview(25)}}</p>
5
 
6
+ {% if post.thumbnail.src %}
7
+ <img src="{{post.thumbnail.src}}" />
8
  {% endif %}
9
  {% endblock %}
timber-starter-theme/views/tease.twig CHANGED
@@ -1,10 +1,10 @@
1
  <article class="tease tease-{{post.post_type}}" id="tease-{{post.ID}}">
2
  {% block content %}
3
- <h2 class="h2"><a href="{{post.get_path}}">{{post.title}}</a></h2>
4
  <p>{{post.get_preview}}</p>
5
 
6
  {% if post.get_thumbnail %}
7
- <img src="{{post.get_thumbnail.get_url}}" />
8
  {% endif %}
9
  {% endblock %}
10
  </article>
1
  <article class="tease tease-{{post.post_type}}" id="tease-{{post.ID}}">
2
  {% block content %}
3
+ <h2 class="h2"><a href="{{post.link}}">{{post.title}}</a></h2>
4
  <p>{{post.get_preview}}</p>
5
 
6
  {% if post.get_thumbnail %}
7
+ <img src="{{post.thumbnail.src}}" />
8
  {% endif %}
9
  {% endblock %}
10
  </article>
timber.php CHANGED
@@ -4,7 +4,7 @@ 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.15.5
8
  Author URI: http://upstatement.com/
9
  */
10
 
@@ -33,6 +33,9 @@ require_once(__DIR__ . '/functions/timber-theme.php');
33
  require_once(__DIR__ . '/functions/timber-loader.php');
34
  require_once(__DIR__ . '/functions/timber-function-wrapper.php');
35
  require_once(__DIR__ . '/functions/integrations/acf-timber.php');
 
 
 
36
 
37
  require_once(__DIR__ . '/admin/timber-admin.php');
38
 
@@ -339,6 +342,7 @@ class Timber {
339
  $data['language_attributes'] = TimberHelper::function_wrapper('language_attributes');
340
  $data['stylesheet_uri'] = get_stylesheet_uri();
341
  $data['template_uri'] = get_template_directory_uri();
 
342
  $data = apply_filters('timber_context', $data);
343
  return $data;
344
  }
@@ -463,16 +467,13 @@ class Timber {
463
  $header_string = "$protocol $force_header $text";
464
  return $header_string;
465
  }, 10, 4 );
466
- add_filter('body_class', function($classes) use ($force_header) {
467
- if (isset($classes) && is_array($classes) && $force_header != 404){
468
- foreach($classes as &$class){
469
- if (strstr($class, '404')){
470
- $class = '';
471
- }
472
  }
473
- }
474
- return $classes;
475
- });
476
  }
477
 
478
  if ($query) {
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.16.0
8
  Author URI: http://upstatement.com/
9
  */
10
 
33
  require_once(__DIR__ . '/functions/timber-loader.php');
34
  require_once(__DIR__ . '/functions/timber-function-wrapper.php');
35
  require_once(__DIR__ . '/functions/integrations/acf-timber.php');
36
+ if ( defined('WP_CLI') && WP_CLI ) {
37
+ require_once(__DIR__ . '/functions/integrations/wpcli-timber.php');
38
+ }
39
 
40
  require_once(__DIR__ . '/admin/timber-admin.php');
41
 
342
  $data['language_attributes'] = TimberHelper::function_wrapper('language_attributes');
343
  $data['stylesheet_uri'] = get_stylesheet_uri();
344
  $data['template_uri'] = get_template_directory_uri();
345
+ $data['theme'] = new TimberTheme();
346
  $data = apply_filters('timber_context', $data);
347
  return $data;
348
  }
467
  $header_string = "$protocol $force_header $text";
468
  return $header_string;
469
  }, 10, 4 );
470
+ if (404 != $force_header) {
471
+ add_action('parse_query', function($query) {
472
+ if ($query->is_main_query()){
473
+ $query->is_404 = false;
 
 
474
  }
475
+ });
476
+ }
 
477
  }
478
 
479
  if ($query) {