Version Description
- More flexiblity for custom routes (thanks @mgmartel)
- Added filters for core objects (TimberPost and TimberTerm). This greatly helps when you need to have retrived custom fields or repeaters interprted as posts or terms
- Renamed "WPHelper" to more namespace-friendly "TimberHelper"
- Added function_wrapper helper to execute functions where they are placed in the template as opposed to when they are generated (@mgmartel)
- You can now have custom fields processed via post.get_field('my_custom_field'). This is a huge help for using things like Advanced Custom Fields' repeater.
- Performance improvements
Download this release
Release Info
Developer | jarednova |
Plugin | Timber |
Version | 0.14.0 |
Comparing to | |
See all releases |
Code changes from version 0.13.5 to 0.14.0
- functions/{functions-wp-helper.php → functions-timber-helper.php} +25 -2
- functions/{functions-wp-image-helper.php → functions-timber-image-helper.php} +6 -3
- functions/functions-twig.php +30 -10
- functions/functions-word-query.php +0 -45
- functions/timber-function-wrapper.php +52 -0
- functions/timber-menu.php +2 -2
- functions/timber-post.php +7 -4
- functions/timber-term.php +1 -1
- functions/timber-user.php +1 -1
- readme.txt +8 -0
- timber-starter-theme/404.php +1 -1
- timber-starter-theme/archive.php +1 -1
- timber-starter-theme/author.php +1 -1
- timber-starter-theme/index.php +9 -3
- timber-starter-theme/page.php +1 -1
- timber-starter-theme/search.php +1 -1
- timber-starter-theme/single.php +2 -2
- timber-starter-theme/views/base.twig +4 -4
- timber-starter-theme/views/html-header.twig +3 -3
- timber-starter-theme/views/index.twig +1 -0
- timber-starter-theme/views/single.twig +2 -2
- timber.php +44 -18
functions/{functions-wp-helper.php → functions-timber-helper.php}
RENAMED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class
|
4 |
|
5 |
public static function transient($slug, $callback, $transient_time = 1800){
|
6 |
if (false===($data = get_transient($slug))){
|
@@ -10,6 +10,22 @@ class WPHelper {
|
|
10 |
return $data;
|
11 |
}
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
public static function is_array_assoc($arr) {
|
14 |
if (!is_array($arr)) {
|
15 |
return false;
|
@@ -32,6 +48,10 @@ class WPHelper {
|
|
32 |
return $data;
|
33 |
}
|
34 |
|
|
|
|
|
|
|
|
|
35 |
public static function is_url($url) {
|
36 |
if (!is_string($url)){
|
37 |
return false;
|
@@ -266,7 +286,7 @@ class WPHelper {
|
|
266 |
return $wpdb->get_var($query);
|
267 |
}
|
268 |
|
269 |
-
/* this $args thing is a fucking mess, fix at some point:
|
270 |
|
271 |
http://codex.wordpress.org/Function_Reference/comment_form */
|
272 |
|
@@ -446,5 +466,8 @@ class WPHelper {
|
|
446 |
endswitch;
|
447 |
return $r;
|
448 |
}
|
|
|
449 |
|
|
|
|
|
450 |
}
|
1 |
<?php
|
2 |
|
3 |
+
class TimberHelper {
|
4 |
|
5 |
public static function transient($slug, $callback, $transient_time = 1800){
|
6 |
if (false===($data = get_transient($slug))){
|
10 |
return $data;
|
11 |
}
|
12 |
|
13 |
+
public static function start_timer(){
|
14 |
+
$time = microtime();
|
15 |
+
$time = explode(' ', $time);
|
16 |
+
$time = $time[1] + $time[0];
|
17 |
+
return $time;
|
18 |
+
}
|
19 |
+
|
20 |
+
public static function stop_timer($start){
|
21 |
+
$time = microtime();
|
22 |
+
$time = explode(' ', $time);
|
23 |
+
$time = $time[1] + $time[0];
|
24 |
+
$finish = $time;
|
25 |
+
$total_time = round(($finish - $start), 4);
|
26 |
+
return 'Page generated in '.$total_time.' seconds.';
|
27 |
+
}
|
28 |
+
|
29 |
public static function is_array_assoc($arr) {
|
30 |
if (!is_array($arr)) {
|
31 |
return false;
|
48 |
return $data;
|
49 |
}
|
50 |
|
51 |
+
public static function function_wrapper($function_name, $defaults = array(), $return_output_buffer = false) {
|
52 |
+
return new TimberFunctionWrapper($function_name, $defaults, $return_output_buffer);
|
53 |
+
}
|
54 |
+
|
55 |
public static function is_url($url) {
|
56 |
if (!is_string($url)){
|
57 |
return false;
|
286 |
return $wpdb->get_var($query);
|
287 |
}
|
288 |
|
289 |
+
/* this $args thing is a fucking mess, fix at some point:
|
290 |
|
291 |
http://codex.wordpress.org/Function_Reference/comment_form */
|
292 |
|
466 |
endswitch;
|
467 |
return $r;
|
468 |
}
|
469 |
+
}
|
470 |
|
471 |
+
class WPHelper extends TimberHelper {
|
472 |
+
//for backwards compat, will remove eventually
|
473 |
}
|
functions/{functions-wp-image-helper.php → functions-timber-image-helper.php}
RENAMED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class
|
4 |
|
5 |
function hexrgb($hexstr) {
|
6 |
$int = hexdec($hexstr);
|
@@ -89,7 +89,7 @@
|
|
89 |
if ($abs){
|
90 |
return untrailingslashit(site_url()).$new_path;
|
91 |
} else {
|
92 |
-
return
|
93 |
}
|
94 |
return $new_path;
|
95 |
}
|
@@ -123,8 +123,11 @@
|
|
123 |
} else if (isset($image->error_data['error_loading_image'])) {
|
124 |
error_log('Error loading '.$image->error_data['error_loading_image']);
|
125 |
} else {
|
126 |
-
|
127 |
}
|
128 |
return $src;
|
129 |
}
|
|
|
|
|
|
|
130 |
}
|
1 |
<?php
|
2 |
|
3 |
+
class TimberImageHelper {
|
4 |
|
5 |
function hexrgb($hexstr) {
|
6 |
$int = hexdec($hexstr);
|
89 |
if ($abs){
|
90 |
return untrailingslashit(site_url()).$new_path;
|
91 |
} else {
|
92 |
+
return TimberHelper::preslashit($new_path);
|
93 |
}
|
94 |
return $new_path;
|
95 |
}
|
123 |
} else if (isset($image->error_data['error_loading_image'])) {
|
124 |
error_log('Error loading '.$image->error_data['error_loading_image']);
|
125 |
} else {
|
126 |
+
TimberHelper::error_log($image);
|
127 |
}
|
128 |
return $src;
|
129 |
}
|
130 |
+
}
|
131 |
+
|
132 |
+
class WPImageHelper extends TimberImageHelper {
|
133 |
}
|
functions/functions-twig.php
CHANGED
@@ -12,9 +12,9 @@ class TimberTwig {
|
|
12 |
*/
|
13 |
function add_twig_filters($twig) {
|
14 |
/* image filters */
|
15 |
-
$twig->addFilter('resize', new Twig_Filter_Function(array('
|
16 |
$twig->addFilter('letterbox', new Twig_Filter_Function('wp_resize_letterbox'));
|
17 |
-
$twig->addFilter('tojpg', new Twig_Filter_Function(array('
|
18 |
$twig->addFilter('get_src_from_attachment_id', new Twig_Filter_Function('twig_get_src_from_attachment_id'));
|
19 |
|
20 |
/* debugging filters */
|
@@ -32,8 +32,8 @@ class TimberTwig {
|
|
32 |
$twig->addFilter('sanitize', new Twig_Filter_Function('sanitize_title'));
|
33 |
$twig->addFilter('shortcodes', new Twig_Filter_Function('twig_shortcodes'));
|
34 |
$twig->addFilter('time_ago', new Twig_Filter_Function('twig_time_ago'));
|
35 |
-
$twig->addFilter('twitterify', new Twig_Filter_Function(array('
|
36 |
-
$twig->addFilter('twitterfy', new Twig_Filter_Function(array('
|
37 |
$twig->addFilter('wp_body_class', new Twig_Filter_Function('twig_body_class'));
|
38 |
$twig->addFilter('wpautop', new Twig_Filter_Function('wpautop'));
|
39 |
|
@@ -50,6 +50,26 @@ class TimberTwig {
|
|
50 |
$twig->addFunction(new Twig_SimpleFunction('function', array(&$this, 'exec_function')));
|
51 |
$twig->addFunction(new Twig_SimpleFunction('fn', array(&$this, 'exec_function')));
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
/* bloginfo and translate */
|
54 |
$twig->addFunction('bloginfo', new Twig_SimpleFunction('bloginfo', function($show = '', $filter = 'raw'){
|
55 |
return get_bloginfo($show, $filter);
|
@@ -119,11 +139,11 @@ function hexrgb($hexstr) {
|
|
119 |
}
|
120 |
|
121 |
function wp_resize_letterbox($src, $w, $h, $color = '#000000') {
|
122 |
-
//$old_file =
|
123 |
$urlinfo = parse_url($src);
|
124 |
$old_file = $_SERVER['DOCUMENT_ROOT'].$urlinfo['path'];
|
125 |
-
$new_file =
|
126 |
-
$new_file_rel =
|
127 |
$new_file_boxed = str_replace('-lb-', '-lbox-', $new_file);
|
128 |
if (file_exists($new_file_boxed)) {
|
129 |
$new_file_rel = str_replace('-lb-', '-lbox-', $new_file_rel);
|
@@ -170,10 +190,10 @@ function wp_resize_letterbox($src, $w, $h, $color = '#000000') {
|
|
170 |
imagecopy($bg, $image, $x, $y, 0, 0, $owt, $oht);
|
171 |
$new_file = str_replace('-lb-', '-lbox-', $new_file);
|
172 |
imagejpeg($bg, $new_file);
|
173 |
-
return
|
174 |
} else {
|
175 |
if (WP_DEBUG){
|
176 |
-
|
177 |
}
|
178 |
}
|
179 |
return null;
|
@@ -238,7 +258,7 @@ function get_calling_script_dir($backtrace) {
|
|
238 |
|
239 |
|
240 |
function twig_get_src_from_attachment_id($aid) {
|
241 |
-
return
|
242 |
}
|
243 |
|
244 |
function twig_get_path($url) {
|
12 |
*/
|
13 |
function add_twig_filters($twig) {
|
14 |
/* image filters */
|
15 |
+
$twig->addFilter('resize', new Twig_Filter_Function(array('TimberImageHelper', 'resize')));
|
16 |
$twig->addFilter('letterbox', new Twig_Filter_Function('wp_resize_letterbox'));
|
17 |
+
$twig->addFilter('tojpg', new Twig_Filter_Function(array('TimberImageHelper', 'img_to_jpg')));
|
18 |
$twig->addFilter('get_src_from_attachment_id', new Twig_Filter_Function('twig_get_src_from_attachment_id'));
|
19 |
|
20 |
/* debugging filters */
|
32 |
$twig->addFilter('sanitize', new Twig_Filter_Function('sanitize_title'));
|
33 |
$twig->addFilter('shortcodes', new Twig_Filter_Function('twig_shortcodes'));
|
34 |
$twig->addFilter('time_ago', new Twig_Filter_Function('twig_time_ago'));
|
35 |
+
$twig->addFilter('twitterify', new Twig_Filter_Function(array('TimberHelper', 'twitterify')));
|
36 |
+
$twig->addFilter('twitterfy', new Twig_Filter_Function(array('TimberHelper', 'twitterify')));
|
37 |
$twig->addFilter('wp_body_class', new Twig_Filter_Function('twig_body_class'));
|
38 |
$twig->addFilter('wpautop', new Twig_Filter_Function('wpautop'));
|
39 |
|
50 |
$twig->addFunction(new Twig_SimpleFunction('function', array(&$this, 'exec_function')));
|
51 |
$twig->addFunction(new Twig_SimpleFunction('fn', array(&$this, 'exec_function')));
|
52 |
|
53 |
+
/* TimberObjects */
|
54 |
+
$twig->addFunction(new Twig_SimpleFunction('TimberPost', function($pid){
|
55 |
+
if (is_array($pid)){
|
56 |
+
foreach($pid as &$p){
|
57 |
+
$p = new TimberPost($p);
|
58 |
+
}
|
59 |
+
return $pid;
|
60 |
+
}
|
61 |
+
return new TimberPost($pid);
|
62 |
+
}));
|
63 |
+
$twig->addFunction(new Twig_SimpleFunction('TimberImage', function($pid){
|
64 |
+
if (is_array($pid)){
|
65 |
+
foreach($pid as &$p){
|
66 |
+
$p = new TimberImage($p);
|
67 |
+
}
|
68 |
+
return $pid;
|
69 |
+
}
|
70 |
+
return new TimberImage($pid);
|
71 |
+
}));
|
72 |
+
|
73 |
/* bloginfo and translate */
|
74 |
$twig->addFunction('bloginfo', new Twig_SimpleFunction('bloginfo', function($show = '', $filter = 'raw'){
|
75 |
return get_bloginfo($show, $filter);
|
139 |
}
|
140 |
|
141 |
function wp_resize_letterbox($src, $w, $h, $color = '#000000') {
|
142 |
+
//$old_file = TimberHelper::get_full_path($src);
|
143 |
$urlinfo = parse_url($src);
|
144 |
$old_file = $_SERVER['DOCUMENT_ROOT'].$urlinfo['path'];
|
145 |
+
$new_file = TimberHelper::get_letterbox_file_path($urlinfo['path'], $w, $h);
|
146 |
+
$new_file_rel = TimberHelper::get_letterbox_file_rel($urlinfo['path'], $w, $h);
|
147 |
$new_file_boxed = str_replace('-lb-', '-lbox-', $new_file);
|
148 |
if (file_exists($new_file_boxed)) {
|
149 |
$new_file_rel = str_replace('-lb-', '-lbox-', $new_file_rel);
|
190 |
imagecopy($bg, $image, $x, $y, 0, 0, $owt, $oht);
|
191 |
$new_file = str_replace('-lb-', '-lbox-', $new_file);
|
192 |
imagejpeg($bg, $new_file);
|
193 |
+
return TimberHelper::get_rel_path($new_file);
|
194 |
} else {
|
195 |
if (WP_DEBUG){
|
196 |
+
TimberHelper::error_log($image);
|
197 |
}
|
198 |
}
|
199 |
return null;
|
258 |
|
259 |
|
260 |
function twig_get_src_from_attachment_id($aid) {
|
261 |
+
return TimberHelper::get_image_path($aid);
|
262 |
}
|
263 |
|
264 |
function twig_get_path($url) {
|
functions/functions-word-query.php
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class WordQuery {
|
4 |
-
|
5 |
-
public function get_posts_multisite($query){
|
6 |
-
add_action('posts_clauses', array(&$this, 'query_info'));
|
7 |
-
}
|
8 |
-
|
9 |
-
public function query_info($query){
|
10 |
-
echo '----QUERY INFO----';
|
11 |
-
print_r($query);
|
12 |
-
}
|
13 |
-
|
14 |
-
public function get_posts_multisite_old($query){
|
15 |
-
if (is_string($query)){
|
16 |
-
parse_str($query, $query);
|
17 |
-
}
|
18 |
-
if (!isset($query['blogs'])){
|
19 |
-
return get_posts($query);
|
20 |
-
}
|
21 |
-
$ids = self::get_blog_ids_from_names($query['blogs']);
|
22 |
-
$results = array();
|
23 |
-
foreach($ids as $id){
|
24 |
-
switch_to_blog($id);
|
25 |
-
$results[] = get_posts($query);
|
26 |
-
}
|
27 |
-
return $results;
|
28 |
-
}
|
29 |
-
|
30 |
-
function get_blog_ids_from_names($blog_names){
|
31 |
-
if (is_string($blog_names)){
|
32 |
-
$blog_names = explode(',', $blog_names);
|
33 |
-
}
|
34 |
-
$ids = array();
|
35 |
-
foreach($blog_names as $blog_name){
|
36 |
-
if (is_numeric($blog_name)){
|
37 |
-
$ids[] = $blog_name;
|
38 |
-
} else (is_string($blog_name)) {
|
39 |
-
$ids[] = get_id_from_blogname($blog_name);
|
40 |
-
}
|
41 |
-
}
|
42 |
-
return $ids;
|
43 |
-
}
|
44 |
-
|
45 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
functions/timber-function-wrapper.php
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class TimberFunctionWrapper
|
4 |
+
{
|
5 |
+
|
6 |
+
private $_function;
|
7 |
+
private $_args;
|
8 |
+
private $_use_ob;
|
9 |
+
|
10 |
+
public function __toString() {
|
11 |
+
return $this->call();
|
12 |
+
}
|
13 |
+
|
14 |
+
public function __construct( $function, $args = array( ), $return_output_buffer = false ) {
|
15 |
+
$this->_function = $function;
|
16 |
+
$this->_args = $args;
|
17 |
+
$this->_use_ob = $return_output_buffer;
|
18 |
+
|
19 |
+
add_filter( 'get_twig', array( &$this, 'add_to_twig' ) );
|
20 |
+
}
|
21 |
+
|
22 |
+
public function add_to_twig( $twig ) {
|
23 |
+
$wrapper = $this;
|
24 |
+
|
25 |
+
$twig->addFunction( new Twig_SimpleFunction( $this->_function, function() use ( $wrapper ) {
|
26 |
+
return call_user_func_array( array( $wrapper, 'call' ), func_get_args() );
|
27 |
+
} ) );
|
28 |
+
|
29 |
+
return $twig;
|
30 |
+
}
|
31 |
+
|
32 |
+
public function call() {
|
33 |
+
$args = $this->_parse_args( func_get_args(), $this->_args );
|
34 |
+
|
35 |
+
if ( $this->_use_ob )
|
36 |
+
return WPHelper::ob_function( $this->_function, $args );
|
37 |
+
else
|
38 |
+
return (string) call_user_func_array( $this->_function, $args );
|
39 |
+
}
|
40 |
+
|
41 |
+
private function _parse_args( $args, $defaults ) {
|
42 |
+
$_arg = reset( $defaults );
|
43 |
+
|
44 |
+
foreach ( $args as $index => $arg ) {
|
45 |
+
$defaults[$index] = is_null( $arg ) ? $_arg : $arg;
|
46 |
+
$_arg = next( $defaults );
|
47 |
+
}
|
48 |
+
|
49 |
+
return $defaults;
|
50 |
+
}
|
51 |
+
|
52 |
+
}
|
functions/timber-menu.php
CHANGED
@@ -24,7 +24,7 @@ class TimberMenu extends TimberCore {
|
|
24 |
$this->import($menu_info);
|
25 |
$this->ID = $this->term_id;
|
26 |
} else {
|
27 |
-
|
28 |
}
|
29 |
return null;
|
30 |
}
|
@@ -46,7 +46,7 @@ class TimberMenu extends TimberCore {
|
|
46 |
$index[$item->ID] = new TimberMenuItem($item);
|
47 |
}
|
48 |
foreach($index as $item) {
|
49 |
-
if($item->menu_item_parent) {
|
50 |
$index[$item->menu_item_parent]->add_child($item);
|
51 |
} else {
|
52 |
$menu[] = $item;
|
24 |
$this->import($menu_info);
|
25 |
$this->ID = $this->term_id;
|
26 |
} else {
|
27 |
+
TimberHelper::error_log("Sorry, the menu you were looking for wasn't found ('".$slug."'). Here's what Timber did find:");
|
28 |
}
|
29 |
return null;
|
30 |
}
|
46 |
$index[$item->ID] = new TimberMenuItem($item);
|
47 |
}
|
48 |
foreach($index as $item) {
|
49 |
+
if($item->menu_item_parent && isset($index[$item->menu_item_parent])) {
|
50 |
$index[$item->menu_item_parent]->add_child($item);
|
51 |
} else {
|
52 |
$menu[] = $item;
|
functions/timber-post.php
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
class TimberPost extends TimberCore {
|
4 |
|
5 |
var $ImageClass = 'TimberImage';
|
@@ -131,14 +131,14 @@ class TimberPost extends TimberCore {
|
|
131 |
$trimmed = false;
|
132 |
if (isset($this->post_excerpt) && strlen($this->post_excerpt)) {
|
133 |
if ($force) {
|
134 |
-
$text =
|
135 |
$trimmed = true;
|
136 |
} else {
|
137 |
$text = $this->post_excerpt;
|
138 |
}
|
139 |
}
|
140 |
if (!strlen($text)) {
|
141 |
-
$text =
|
142 |
$trimmed = true;
|
143 |
}
|
144 |
if (!strlen(trim($text))) {
|
@@ -426,7 +426,10 @@ class TimberPost extends TimberCore {
|
|
426 |
|
427 |
//This is for integration with Elliot Condon's wonderful ACF
|
428 |
function get_field($field_name) {
|
429 |
-
|
|
|
|
|
|
|
430 |
}
|
431 |
|
432 |
function import_field($field_name) {
|
1 |
<?php
|
2 |
+
|
3 |
class TimberPost extends TimberCore {
|
4 |
|
5 |
var $ImageClass = 'TimberImage';
|
131 |
$trimmed = false;
|
132 |
if (isset($this->post_excerpt) && strlen($this->post_excerpt)) {
|
133 |
if ($force) {
|
134 |
+
$text = TimberHelper::trim_words($this->post_excerpt, $len);
|
135 |
$trimmed = true;
|
136 |
} else {
|
137 |
$text = $this->post_excerpt;
|
138 |
}
|
139 |
}
|
140 |
if (!strlen($text)) {
|
141 |
+
$text = TimberHelper::trim_words($this->get_content(), $len, false);
|
142 |
$trimmed = true;
|
143 |
}
|
144 |
if (!strlen(trim($text))) {
|
426 |
|
427 |
//This is for integration with Elliot Condon's wonderful ACF
|
428 |
function get_field($field_name) {
|
429 |
+
if (function_exists('get_field')){
|
430 |
+
return get_field($field_name, $this->ID);
|
431 |
+
}
|
432 |
+
return get_post_meta($this->ID, $field, true);
|
433 |
}
|
434 |
|
435 |
function import_field($field_name) {
|
functions/timber-term.php
CHANGED
@@ -35,7 +35,7 @@ class TimberTerm extends TimberCore {
|
|
35 |
$term->ID = $term->term_id;
|
36 |
} else if (is_string($tid)) {
|
37 |
echo 'bad call using '.$tid;
|
38 |
-
//
|
39 |
}
|
40 |
if (function_exists('get_fields')) {
|
41 |
//lets get whatever we can from advanced custom fields;
|
35 |
$term->ID = $term->term_id;
|
36 |
} else if (is_string($tid)) {
|
37 |
echo 'bad call using '.$tid;
|
38 |
+
//TimberHelper::error_log(debug_backtrace());
|
39 |
}
|
40 |
if (function_exists('get_fields')) {
|
41 |
//lets get whatever we can from advanced custom fields;
|
functions/timber-user.php
CHANGED
@@ -7,7 +7,7 @@ class TimberUser extends TimberCore {
|
|
7 |
}
|
8 |
|
9 |
public function get_link() {
|
10 |
-
$p =
|
11 |
return $p . 'author/' . $this->slug();
|
12 |
}
|
13 |
|
7 |
}
|
8 |
|
9 |
public function get_link() {
|
10 |
+
$p = TimberHelper::get_path_base();
|
11 |
return $p . 'author/' . $this->slug();
|
12 |
}
|
13 |
|
readme.txt
CHANGED
@@ -37,6 +37,14 @@ Timber is great for any WordPress developer who cares about writing good, mainta
|
|
37 |
|
38 |
== Changelog ==
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
= 0.13.5 =
|
41 |
* Added comprehensive support for actions and filters (thanks @mgmartel)
|
42 |
* Rewrote routing to template to be 100% harmonious with WordPress (thanks again @mgmartel)
|
37 |
|
38 |
== Changelog ==
|
39 |
|
40 |
+
= 0.14.0 =
|
41 |
+
* More flexiblity for custom routes (thanks @mgmartel)
|
42 |
+
* Added filters for core objects (TimberPost and TimberTerm). This greatly helps when you need to have retrived custom fields or repeaters interprted as posts or terms
|
43 |
+
* Renamed "WPHelper" to more namespace-friendly "TimberHelper"
|
44 |
+
* Added function_wrapper helper to execute functions where they are placed in the template as opposed to when they are generated (@mgmartel)
|
45 |
+
* You can now have custom fields processed via post.get_field('my_custom_field'). This is a huge help for using things like Advanced Custom Fields' repeater.
|
46 |
+
* Performance improvements
|
47 |
+
|
48 |
= 0.13.5 =
|
49 |
* Added comprehensive support for actions and filters (thanks @mgmartel)
|
50 |
* Rewrote routing to template to be 100% harmonious with WordPress (thanks again @mgmartel)
|
timber-starter-theme/404.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/**
|
3 |
* The template for displaying 404 pages (Not Found)
|
4 |
*
|
5 |
-
* Methods for
|
6 |
*
|
7 |
* @package WordPress
|
8 |
* @subpackage Timber
|
2 |
/**
|
3 |
* The template for displaying 404 pages (Not Found)
|
4 |
*
|
5 |
+
* Methods for TimberHelper can be found in the /functions sub-directory
|
6 |
*
|
7 |
* @package WordPress
|
8 |
* @subpackage Timber
|
timber-starter-theme/archive.php
CHANGED
@@ -7,7 +7,7 @@
|
|
7 |
*
|
8 |
* Learn more: http://codex.wordpress.org/Template_Hierarchy
|
9 |
*
|
10 |
-
* Methods for
|
11 |
*
|
12 |
* @package WordPress
|
13 |
* @subpackage Timber
|
7 |
*
|
8 |
* Learn more: http://codex.wordpress.org/Template_Hierarchy
|
9 |
*
|
10 |
+
* Methods for TimberHelper can be found in the /functions sub-directory
|
11 |
*
|
12 |
* @package WordPress
|
13 |
* @subpackage Timber
|
timber-starter-theme/author.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/**
|
3 |
* The template for displaying Author Archive pages
|
4 |
*
|
5 |
-
* Methods for
|
6 |
*
|
7 |
* @package WordPress
|
8 |
* @subpackage Timber
|
2 |
/**
|
3 |
* The template for displaying Author Archive pages
|
4 |
*
|
5 |
+
* Methods for TimberHelper can be found in the /functions sub-directory
|
6 |
*
|
7 |
* @package WordPress
|
8 |
* @subpackage Timber
|
timber-starter-theme/index.php
CHANGED
@@ -4,9 +4,9 @@
|
|
4 |
* This is the most generic template file in a WordPress theme
|
5 |
* and one of the two required files for a theme (the other being style.css).
|
6 |
* It is used to display a page when nothing more specific matches a query.
|
7 |
-
* E.g., it puts together the home page when no home.php file
|
8 |
*
|
9 |
-
* Methods for
|
10 |
*
|
11 |
* @package WordPress
|
12 |
* @subpackage Timber
|
@@ -16,10 +16,16 @@
|
|
16 |
if (!class_exists('Timber')){
|
17 |
echo 'Timber not activated';
|
18 |
}
|
19 |
-
|
20 |
$data = Timber::get_context();
|
|
|
21 |
$posts = Timber::get_posts('TimberPost');
|
22 |
$data['posts'] = $posts;
|
|
|
|
|
|
|
|
|
|
|
23 |
Timber::render('index.twig', $data);
|
24 |
|
25 |
|
4 |
* This is the most generic template file in a WordPress theme
|
5 |
* and one of the two required files for a theme (the other being style.css).
|
6 |
* It is used to display a page when nothing more specific matches a query.
|
7 |
+
* E.g., it puts together the home page when no home.php file
|
8 |
*
|
9 |
+
* Methods for TimberHelper can be found in the /functions sub-directory
|
10 |
*
|
11 |
* @package WordPress
|
12 |
* @subpackage Timber
|
16 |
if (!class_exists('Timber')){
|
17 |
echo 'Timber not activated';
|
18 |
}
|
19 |
+
|
20 |
$data = Timber::get_context();
|
21 |
+
$data['menu'] = new TimberMenu();
|
22 |
$posts = Timber::get_posts('TimberPost');
|
23 |
$data['posts'] = $posts;
|
24 |
+
$data['foo'] = 'bar';
|
25 |
+
$templates = array('index.twig');
|
26 |
+
if (is_home()){
|
27 |
+
array_unshift($templates, 'home.twig');
|
28 |
+
}
|
29 |
Timber::render('index.twig', $data);
|
30 |
|
31 |
|
timber-starter-theme/page.php
CHANGED
@@ -14,7 +14,7 @@
|
|
14 |
* /mytheme/page-mypage.php
|
15 |
* (in which case you'll want to duplicate this file and save to the above path)
|
16 |
*
|
17 |
-
* Methods for
|
18 |
*
|
19 |
* @package WordPress
|
20 |
* @subpackage Timber
|
14 |
* /mytheme/page-mypage.php
|
15 |
* (in which case you'll want to duplicate this file and save to the above path)
|
16 |
*
|
17 |
+
* Methods for TimberHelper can be found in the /functions sub-directory
|
18 |
*
|
19 |
* @package WordPress
|
20 |
* @subpackage Timber
|
timber-starter-theme/search.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/**
|
3 |
* Search results page
|
4 |
*
|
5 |
-
* Methods for
|
6 |
*
|
7 |
* @package WordPress
|
8 |
* @subpackage Timber
|
2 |
/**
|
3 |
* Search results page
|
4 |
*
|
5 |
+
* Methods for TimberHelper can be found in the /functions sub-directory
|
6 |
*
|
7 |
* @package WordPress
|
8 |
* @subpackage Timber
|
timber-starter-theme/single.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/**
|
3 |
* The Template for displaying all single posts
|
4 |
*
|
5 |
-
* Methods for
|
6 |
*
|
7 |
* @package WordPress
|
8 |
* @subpackage Timber
|
@@ -13,6 +13,6 @@ $context = Timber::get_context();
|
|
13 |
$post = new TimberPost();
|
14 |
$context['post'] = $post;
|
15 |
$context['wp_title'] .= ' - ' . $post->post_title;
|
16 |
-
$context['comment_form'] =
|
17 |
|
18 |
Timber::render(array('single-' . $post->post_type . '.twig', 'single.twig'), $context);
|
2 |
/**
|
3 |
* The Template for displaying all single posts
|
4 |
*
|
5 |
+
* Methods for TimberHelper can be found in the /functions sub-directory
|
6 |
*
|
7 |
* @package WordPress
|
8 |
* @subpackage Timber
|
13 |
$post = new TimberPost();
|
14 |
$context['post'] = $post;
|
15 |
$context['wp_title'] .= ' - ' . $post->post_title;
|
16 |
+
$context['comment_form'] = TimberHelper::get_comment_form();
|
17 |
|
18 |
Timber::render(array('single-' . $post->post_type . '.twig', 'single.twig'), $context);
|
timber-starter-theme/views/base.twig
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
-
{% include 'html-header.twig' %}
|
2 |
{% block head %}
|
3 |
-
{% endblock %}
|
4 |
</head>
|
5 |
<body class="{{body_class}}" data-source="base.twig">
|
6 |
<header class="header" >
|
@@ -14,7 +14,7 @@
|
|
14 |
<nav id="access" class="ink-navigation" role="navigation">
|
15 |
{{wp_nav_menu}}
|
16 |
</nav><!-- #access -->
|
17 |
-
|
18 |
</div>
|
19 |
{% endblock %}
|
20 |
</header>
|
@@ -37,6 +37,6 @@
|
|
37 |
<footer id="footer">
|
38 |
{% include 'footer.twig' %}
|
39 |
</footer>
|
40 |
-
{{ wp_footer }}
|
41 |
</body>
|
42 |
</html>
|
1 |
+
{% include 'html-header.twig' %}
|
2 |
{% block head %}
|
3 |
+
{% endblock %}
|
4 |
</head>
|
5 |
<body class="{{body_class}}" data-source="base.twig">
|
6 |
<header class="header" >
|
14 |
<nav id="access" class="ink-navigation" role="navigation">
|
15 |
{{wp_nav_menu}}
|
16 |
</nav><!-- #access -->
|
17 |
+
|
18 |
</div>
|
19 |
{% endblock %}
|
20 |
</header>
|
37 |
<footer id="footer">
|
38 |
{% include 'footer.twig' %}
|
39 |
</footer>
|
40 |
+
{{ function('wp_footer') }}
|
41 |
</body>
|
42 |
</html>
|
timber-starter-theme/views/html-header.twig
CHANGED
@@ -3,13 +3,13 @@
|
|
3 |
<!--[if IE 7]><html class="no-js ie ie7 lt-ie9 lt-ie8" {{language_attributes}}> <![endif]-->
|
4 |
<!--[if IE 8]><html class="no-js ie ie8 lt-ie9" {{language_attributes}}> <![endif]-->
|
5 |
<!--[if gt IE 8]><!--><html class="no-js" {{language_attributes}}> <!--<![endif]-->
|
6 |
-
|
7 |
<meta charset="{{ bloginfo('charset') }}" />
|
8 |
<title>{{wp_title}}</title>
|
9 |
<meta name="description" content="{{ bloginfo('description') }}">
|
10 |
<link rel="stylesheet" href="{{ stylesheet_uri }}" type="text/css" media="screen" />
|
11 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
12 |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
13 |
-
|
14 |
<link rel="pingback" href="{{ bloginfo('pingback_url') }}" />
|
15 |
-
|
3 |
<!--[if IE 7]><html class="no-js ie ie7 lt-ie9 lt-ie8" {{language_attributes}}> <![endif]-->
|
4 |
<!--[if IE 8]><html class="no-js ie ie8 lt-ie9" {{language_attributes}}> <![endif]-->
|
5 |
<!--[if gt IE 8]><!--><html class="no-js" {{language_attributes}}> <!--<![endif]-->
|
6 |
+
<head>
|
7 |
<meta charset="{{ bloginfo('charset') }}" />
|
8 |
<title>{{wp_title}}</title>
|
9 |
<meta name="description" content="{{ bloginfo('description') }}">
|
10 |
<link rel="stylesheet" href="{{ stylesheet_uri }}" type="text/css" media="screen" />
|
11 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
12 |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
13 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
14 |
<link rel="pingback" href="{{ bloginfo('pingback_url') }}" />
|
15 |
+
{{function('wp_head')}}
|
timber-starter-theme/views/index.twig
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
{% extends "base.twig" %}
|
2 |
|
3 |
{% block content %}
|
|
|
4 |
{% for post in posts %}
|
5 |
{% include ['tease-'~post.post_type~'.twig', 'tease.twig'] %}
|
6 |
{% endfor %}
|
1 |
{% extends "base.twig" %}
|
2 |
|
3 |
{% block content %}
|
4 |
+
<h2>{{foo}}</h2>
|
5 |
{% for post in posts %}
|
6 |
{% include ['tease-'~post.post_type~'.twig', 'tease.twig'] %}
|
7 |
{% endfor %}
|
timber-starter-theme/views/single.twig
CHANGED
@@ -6,7 +6,7 @@
|
|
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>•</span> {{ post.display_date }}
|
12 |
</p>
|
@@ -22,7 +22,7 @@
|
|
22 |
{{ comment_form }}
|
23 |
</div>
|
24 |
<div class="responses">
|
25 |
-
|
26 |
{% for cmt in post.get_comments() %}
|
27 |
{% include "comment.twig" with {comment:cmt} %}
|
28 |
{% endfor %}
|
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>•</span> {{ post.display_date }}
|
12 |
</p>
|
22 |
{{ comment_form }}
|
23 |
</div>
|
24 |
<div class="responses">
|
25 |
+
|
26 |
{% for cmt in post.get_comments() %}
|
27 |
{% include "comment.twig" with {comment:cmt} %}
|
28 |
{% endfor %}
|
timber.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Timber
|
4 |
Description: The WordPress Timber Library allows you to write themes using the power Twig templates
|
5 |
Author: Jared Novack + Upstatement
|
6 |
-
Version: 0.
|
7 |
Author URI: http://timber.upstatement.com/
|
8 |
*/
|
9 |
|
@@ -11,8 +11,8 @@ global $wp_version;
|
|
11 |
global $timber;
|
12 |
|
13 |
require_once(__DIR__ . '/functions/functions-twig.php');
|
14 |
-
require_once(__DIR__ . '/functions/functions-
|
15 |
-
require_once(__DIR__ . '/functions/functions-
|
16 |
|
17 |
require_once(__DIR__ . '/functions/timber-core.php');
|
18 |
require_once(__DIR__ . '/functions/timber-post.php');
|
@@ -24,6 +24,7 @@ require_once(__DIR__ . '/functions/timber-image.php');
|
|
24 |
require_once(__DIR__ . '/functions/timber-menu.php');
|
25 |
|
26 |
require_once(__DIR__ . '/functions/timber-loader.php');
|
|
|
27 |
|
28 |
require_once(__DIR__ . '/admin/timber-admin.php');
|
29 |
|
@@ -51,10 +52,20 @@ class Timber {
|
|
51 |
protected $router;
|
52 |
|
53 |
public function __construct(){
|
|
|
54 |
$this->init_constants();
|
55 |
add_action('init', array(&$this, 'init_routes'));
|
56 |
}
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
protected function init_constants() {
|
59 |
$timber_loc = str_replace(realpath($_SERVER['DOCUMENT_ROOT']), '', realpath(__DIR__));
|
60 |
$plugin_url_path = str_replace($_SERVER['HTTP_HOST'], '', plugins_url());
|
@@ -90,7 +101,7 @@ class Timber {
|
|
90 |
$PostClass = $query;
|
91 |
$query = false;
|
92 |
}
|
93 |
-
if (
|
94 |
// we have a regularly formed WP query string or array to use
|
95 |
return self::get_posts_from_wp_query($query, $PostClass);
|
96 |
} else if (is_string($query) && !is_integer($query)) {
|
@@ -112,7 +123,7 @@ class Timber {
|
|
112 |
return null;
|
113 |
} else {
|
114 |
error_log('I have failed you! in timber.php::94');
|
115 |
-
|
116 |
}
|
117 |
return $query;
|
118 |
}
|
@@ -177,10 +188,7 @@ class Timber {
|
|
177 |
if (!is_array($query) || !count($query)) {
|
178 |
return null;
|
179 |
}
|
180 |
-
|
181 |
-
$query_list = implode(', ', $query);
|
182 |
-
$results = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE ID IN ($query_list)");
|
183 |
-
$results = array_intersect($query, $results);
|
184 |
return self::handle_post_results($results, $PostClass);
|
185 |
}
|
186 |
|
@@ -244,7 +252,7 @@ class Timber {
|
|
244 |
//its just a string with a single taxonomy
|
245 |
$parsed = TimberTermGetter::get_term_query_from_string($args);
|
246 |
return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
|
247 |
-
} else if (is_array($args) &&
|
248 |
//its an associative array, like a good ole query
|
249 |
$parsed = TimberTermGetter::get_term_query_from_assoc_array($args);
|
250 |
return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
|
@@ -274,14 +282,14 @@ class Timber {
|
|
274 |
$data = array();
|
275 |
$data['http_host'] = 'http://' . $_SERVER['HTTP_HOST'];
|
276 |
$data['wp_title'] = get_bloginfo('name');
|
277 |
-
$data['wp_head'] =
|
278 |
-
$data['wp_footer'] =
|
279 |
$data['body_class'] = implode(' ', get_body_class());
|
280 |
if (function_exists('wp_nav_menu')) {
|
281 |
$data['wp_nav_menu'] = wp_nav_menu(array('container_class' => 'menu-header', 'echo' => false, 'menu_class' => 'nav-menu'));
|
282 |
}
|
283 |
$data['theme_dir'] = str_replace($_SERVER['DOCUMENT_ROOT'], '', get_stylesheet_directory());
|
284 |
-
$data['language_attributes'] =
|
285 |
$data['stylesheet_uri'] = get_stylesheet_uri();
|
286 |
$data['template_uri'] = get_template_directory_uri();
|
287 |
$data = apply_filters('timber_context', $data);
|
@@ -341,7 +349,7 @@ class Timber {
|
|
341 |
================================ */
|
342 |
|
343 |
public static function get_widgets($widget_id){
|
344 |
-
return
|
345 |
}
|
346 |
|
347 |
|
@@ -371,13 +379,31 @@ class Timber {
|
|
371 |
$timber->router->map($route, $callback);
|
372 |
}
|
373 |
|
374 |
-
|
|
|
375 |
$template = locate_template($template);
|
376 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
377 |
if ($query) {
|
378 |
-
add_action('do_parse_request',function() use ($query) {
|
379 |
global $wp;
|
380 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
381 |
return false;
|
382 |
});
|
383 |
}
|
@@ -408,7 +434,7 @@ class Timber {
|
|
408 |
$args['base'] = trailingslashit(get_pagenum_link(0)).'%_%';
|
409 |
$args['prev_next'] = false;
|
410 |
$args = array_merge($args, $prefs);
|
411 |
-
$data['pages'] =
|
412 |
$next = next_posts($args['total'], false);
|
413 |
if ($next){
|
414 |
$data['next'] = array('link' => $next);
|
3 |
Plugin Name: Timber
|
4 |
Description: The WordPress Timber Library allows you to write themes using the power Twig templates
|
5 |
Author: Jared Novack + Upstatement
|
6 |
+
Version: 0.14.0
|
7 |
Author URI: http://timber.upstatement.com/
|
8 |
*/
|
9 |
|
11 |
global $timber;
|
12 |
|
13 |
require_once(__DIR__ . '/functions/functions-twig.php');
|
14 |
+
require_once(__DIR__ . '/functions/functions-timber-helper.php');
|
15 |
+
require_once(__DIR__ . '/functions/functions-timber-image-helper.php');
|
16 |
|
17 |
require_once(__DIR__ . '/functions/timber-core.php');
|
18 |
require_once(__DIR__ . '/functions/timber-post.php');
|
24 |
require_once(__DIR__ . '/functions/timber-menu.php');
|
25 |
|
26 |
require_once(__DIR__ . '/functions/timber-loader.php');
|
27 |
+
require_once(__DIR__ . '/functions/timber-function-wrapper.php');
|
28 |
|
29 |
require_once(__DIR__ . '/admin/timber-admin.php');
|
30 |
|
52 |
protected $router;
|
53 |
|
54 |
public function __construct(){
|
55 |
+
$this->test_compatibility();
|
56 |
$this->init_constants();
|
57 |
add_action('init', array(&$this, 'init_routes'));
|
58 |
}
|
59 |
|
60 |
+
protected function test_compatibility(){
|
61 |
+
if (is_admin() || $_SERVER['PHP_SELF'] == '/wp-login.php'){
|
62 |
+
return;
|
63 |
+
}
|
64 |
+
if (version_compare(phpversion(), '5.3.0', '<') && !is_admin()) {
|
65 |
+
trigger_error('Timber requires PHP 5.3.0 or greater. You have '.phpversion(), E_USER_ERROR);
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
protected function init_constants() {
|
70 |
$timber_loc = str_replace(realpath($_SERVER['DOCUMENT_ROOT']), '', realpath(__DIR__));
|
71 |
$plugin_url_path = str_replace($_SERVER['HTTP_HOST'], '', plugins_url());
|
101 |
$PostClass = $query;
|
102 |
$query = false;
|
103 |
}
|
104 |
+
if (TimberHelper::is_array_assoc($query) || (is_string($query) && strstr($query, '='))) {
|
105 |
// we have a regularly formed WP query string or array to use
|
106 |
return self::get_posts_from_wp_query($query, $PostClass);
|
107 |
} else if (is_string($query) && !is_integer($query)) {
|
123 |
return null;
|
124 |
} else {
|
125 |
error_log('I have failed you! in timber.php::94');
|
126 |
+
TimberHelper::error_log($query);
|
127 |
}
|
128 |
return $query;
|
129 |
}
|
188 |
if (!is_array($query) || !count($query)) {
|
189 |
return null;
|
190 |
}
|
191 |
+
$results = get_posts(array('post_type'=>'any', 'post__in' =>$query, 'orderby' => 'post__in'));
|
|
|
|
|
|
|
192 |
return self::handle_post_results($results, $PostClass);
|
193 |
}
|
194 |
|
252 |
//its just a string with a single taxonomy
|
253 |
$parsed = TimberTermGetter::get_term_query_from_string($args);
|
254 |
return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
|
255 |
+
} else if (is_array($args) && TimberHelper::is_array_assoc($args)){
|
256 |
//its an associative array, like a good ole query
|
257 |
$parsed = TimberTermGetter::get_term_query_from_assoc_array($args);
|
258 |
return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
|
282 |
$data = array();
|
283 |
$data['http_host'] = 'http://' . $_SERVER['HTTP_HOST'];
|
284 |
$data['wp_title'] = get_bloginfo('name');
|
285 |
+
$data['wp_head'] = TimberHelper::function_wrapper('wp_head');
|
286 |
+
$data['wp_footer'] = TimberHelper::function_wrapper('wp_footer');
|
287 |
$data['body_class'] = implode(' ', get_body_class());
|
288 |
if (function_exists('wp_nav_menu')) {
|
289 |
$data['wp_nav_menu'] = wp_nav_menu(array('container_class' => 'menu-header', 'echo' => false, 'menu_class' => 'nav-menu'));
|
290 |
}
|
291 |
$data['theme_dir'] = str_replace($_SERVER['DOCUMENT_ROOT'], '', get_stylesheet_directory());
|
292 |
+
$data['language_attributes'] = TimberHelper::function_wrapper('language_attributes');
|
293 |
$data['stylesheet_uri'] = get_stylesheet_uri();
|
294 |
$data['template_uri'] = get_template_directory_uri();
|
295 |
$data = apply_filters('timber_context', $data);
|
349 |
================================ */
|
350 |
|
351 |
public static function get_widgets($widget_id){
|
352 |
+
return TimberHelper::ob_function('dynamic_sidebar', array($widget_id));
|
353 |
}
|
354 |
|
355 |
|
379 |
$timber->router->map($route, $callback);
|
380 |
}
|
381 |
|
382 |
+
|
383 |
+
public static function load_template($template, $query = false, $force_header = 0) {
|
384 |
$template = locate_template($template);
|
385 |
|
386 |
+
if ($force_header) {
|
387 |
+
add_filter('status_header', function($status_header, $header, $text, $protocol) use ($force_header) {
|
388 |
+
$text = get_status_header_desc($force_header);
|
389 |
+
return "$protocol $force_header $text";
|
390 |
+
}, 10, 4 );
|
391 |
+
}
|
392 |
+
|
393 |
if ($query) {
|
394 |
+
add_action('do_parse_request', function() use ($query) {
|
395 |
global $wp;
|
396 |
+
|
397 |
+
if ( is_callable($query) )
|
398 |
+
$query = call_user_func($query);
|
399 |
+
|
400 |
+
if ( is_array($query) )
|
401 |
+
$wp->query_vars = $query;
|
402 |
+
elseif ( !empty($query) )
|
403 |
+
parse_str($query, $wp->query_vars);
|
404 |
+
else
|
405 |
+
return true; // Could not interpret query. Let WP try.
|
406 |
+
|
407 |
return false;
|
408 |
});
|
409 |
}
|
434 |
$args['base'] = trailingslashit(get_pagenum_link(0)).'%_%';
|
435 |
$args['prev_next'] = false;
|
436 |
$args = array_merge($args, $prefs);
|
437 |
+
$data['pages'] = TimberHelper::paginate_links($args);
|
438 |
$next = next_posts($args['total'], false);
|
439 |
if ($next){
|
440 |
$data['next'] = array('link' => $next);
|