Version Description
Download this release
Release Info
Developer | jarednova |
Plugin | Timber |
Version | 1.2.1 |
Comparing to | |
See all releases |
Code changes from version 1.2.0 to 1.2.1
- lib/Admin.php +34 -12
- lib/Integrations/CoAuthorsPlus.php +1 -1
- lib/Pagination.php +43 -32
- lib/Theme.php +14 -15
- lib/Timber.php +1 -1
- lib/URLHelper.php +27 -5
- readme.txt +2 -2
- timber.php +1 -1
lib/Admin.php
CHANGED
@@ -30,6 +30,9 @@ class Admin {
|
|
30 |
return $links;
|
31 |
}
|
32 |
|
|
|
|
|
|
|
33 |
protected static function disable_update() {
|
34 |
$m = '<br>Is your theme in active development? That is, is someone actively in PHP files writing new code? If you answered "no", then <i>DO NOT UPGRADE</i>. ';
|
35 |
$m .= "We're so serious about it, we've even disabled the update link. If you really really think you should upgrade you can still <a href='https://wordpress.org/plugins/timber-library/'>download from WordPress.org</a>, but that's on you!";
|
@@ -38,6 +41,9 @@ class Admin {
|
|
38 |
return $m;
|
39 |
}
|
40 |
|
|
|
|
|
|
|
41 |
protected static function update_message_milestone() {
|
42 |
$m = '<br><b>Warning:</b> Timber 1.0 removed a number of features and methods. Before upgrading please test your theme on a local or staging site to ensure that your theme will work with the newest version.<br>
|
43 |
|
@@ -50,23 +56,42 @@ class Admin {
|
|
50 |
return $m;
|
51 |
}
|
52 |
|
|
|
|
|
|
|
53 |
protected static function update_message_major() {
|
54 |
$m = '<br><b>Warning:</b> This new version of Timber introduces some major new features which might have unknown effects on your site.';
|
55 |
|
56 |
-
|
57 |
$m .= self::disable_update();
|
58 |
return $m;
|
59 |
}
|
60 |
|
|
|
|
|
|
|
61 |
protected static function update_message_minor() {
|
62 |
$m = "<br><b>Warning:</b> This new version of Timber introduces some new features which might have unknown effects on your site. We have automated tests to help us catch potential issues, but nothing is 100%. You're likley safe to upgrade, but do so very carefully and only if you have an experienced WordPress developer available to help you debug potential issues.";
|
63 |
return $m;
|
64 |
}
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
/**
|
67 |
* Displays an update message for plugin list screens.
|
68 |
* Shows only the version updates from the current until the newest version
|
69 |
-
*
|
70 |
* @codeCoverageIgnore
|
71 |
*
|
72 |
* @type function
|
@@ -77,25 +102,22 @@ class Admin {
|
|
77 |
*/
|
78 |
public static function in_plugin_update_message( $plugin_data, $r ) {
|
79 |
$current_version = $plugin_data['Version'];
|
80 |
-
$current_version_array = explode('.', (string)$current_version);
|
81 |
$new_version = $plugin_data['new_version'];
|
82 |
-
$
|
83 |
-
if ( $
|
84 |
-
//milestone version
|
85 |
$message = self::update_message_milestone();
|
86 |
echo '<br />'.sprintf($message);
|
87 |
-
|
|
|
88 |
//major version
|
89 |
$message = self::update_message_major();
|
90 |
echo '<br />'.sprintf($message);
|
91 |
-
|
92 |
-
$new_version_array[2] > $current_version_array[2] ) {
|
93 |
-
$message = self::update_message_minor();
|
94 |
-
echo '<br />'.($message);
|
95 |
}
|
|
|
|
|
96 |
return;
|
97 |
|
98 |
-
|
99 |
}
|
100 |
|
101 |
}
|
30 |
return $links;
|
31 |
}
|
32 |
|
33 |
+
/**
|
34 |
+
* @codeCoverageIgnore
|
35 |
+
*/
|
36 |
protected static function disable_update() {
|
37 |
$m = '<br>Is your theme in active development? That is, is someone actively in PHP files writing new code? If you answered "no", then <i>DO NOT UPGRADE</i>. ';
|
38 |
$m .= "We're so serious about it, we've even disabled the update link. If you really really think you should upgrade you can still <a href='https://wordpress.org/plugins/timber-library/'>download from WordPress.org</a>, but that's on you!";
|
41 |
return $m;
|
42 |
}
|
43 |
|
44 |
+
/**
|
45 |
+
* @codeCoverageIgnore
|
46 |
+
*/
|
47 |
protected static function update_message_milestone() {
|
48 |
$m = '<br><b>Warning:</b> Timber 1.0 removed a number of features and methods. Before upgrading please test your theme on a local or staging site to ensure that your theme will work with the newest version.<br>
|
49 |
|
56 |
return $m;
|
57 |
}
|
58 |
|
59 |
+
/**
|
60 |
+
* @codeCoverageIgnore
|
61 |
+
*/
|
62 |
protected static function update_message_major() {
|
63 |
$m = '<br><b>Warning:</b> This new version of Timber introduces some major new features which might have unknown effects on your site.';
|
64 |
|
65 |
+
|
66 |
$m .= self::disable_update();
|
67 |
return $m;
|
68 |
}
|
69 |
|
70 |
+
/**
|
71 |
+
* @codeCoverageIgnore
|
72 |
+
*/
|
73 |
protected static function update_message_minor() {
|
74 |
$m = "<br><b>Warning:</b> This new version of Timber introduces some new features which might have unknown effects on your site. We have automated tests to help us catch potential issues, but nothing is 100%. You're likley safe to upgrade, but do so very carefully and only if you have an experienced WordPress developer available to help you debug potential issues.";
|
75 |
return $m;
|
76 |
}
|
77 |
|
78 |
+
public static function get_upgrade_magnitude( $current_version, $new_version ) {
|
79 |
+
$current_version_array = explode('.', (string)$current_version);
|
80 |
+
$new_version_array = explode('.', (string)$new_version);
|
81 |
+
if ( $new_version_array[0] > $current_version_array[0]) {
|
82 |
+
return 'milestone';
|
83 |
+
} elseif ( $new_version_array[1] > $current_version_array[1] ) {
|
84 |
+
return 'major';
|
85 |
+
} elseif ( isset($new_version_array[2]) && isset($current_version_array[2]) && $new_version_array[2] > $current_version_array[2] ) {
|
86 |
+
return 'minor';
|
87 |
+
}
|
88 |
+
return 'unknown';
|
89 |
+
}
|
90 |
+
|
91 |
/**
|
92 |
* Displays an update message for plugin list screens.
|
93 |
* Shows only the version updates from the current until the newest version
|
94 |
+
*
|
95 |
* @codeCoverageIgnore
|
96 |
*
|
97 |
* @type function
|
102 |
*/
|
103 |
public static function in_plugin_update_message( $plugin_data, $r ) {
|
104 |
$current_version = $plugin_data['Version'];
|
|
|
105 |
$new_version = $plugin_data['new_version'];
|
106 |
+
$upgrade_magnitude = self::get_upgrade_magnitude($current_version, $new_version);
|
107 |
+
if ( $upgrade_magnitude == 'milestone' ) {
|
|
|
108 |
$message = self::update_message_milestone();
|
109 |
echo '<br />'.sprintf($message);
|
110 |
+
return;
|
111 |
+
} elseif ( $upgrade_magnitude == 'major' ) {
|
112 |
//major version
|
113 |
$message = self::update_message_major();
|
114 |
echo '<br />'.sprintf($message);
|
115 |
+
return;
|
|
|
|
|
|
|
116 |
}
|
117 |
+
$message = self::update_message_minor();
|
118 |
+
echo '<br />'.($message);
|
119 |
return;
|
120 |
|
|
|
121 |
}
|
122 |
|
123 |
}
|
lib/Integrations/CoAuthorsPlus.php
CHANGED
@@ -53,7 +53,7 @@ class CoAuthorsPlus {
|
|
53 |
return null;
|
54 |
}
|
55 |
} else {
|
56 |
-
return $cauthor->
|
57 |
}
|
58 |
}
|
59 |
}
|
53 |
return null;
|
54 |
}
|
55 |
} else {
|
56 |
+
return $cauthor->ID;
|
57 |
}
|
58 |
}
|
59 |
}
|
lib/Pagination.php
CHANGED
@@ -44,17 +44,21 @@ class Pagination {
|
|
44 |
|
45 |
$args['total'] = ceil($wp_query->found_posts / $ppp);
|
46 |
if ( $wp_rewrite->using_permalinks() ) {
|
47 |
-
$url = explode('?', get_pagenum_link(0));
|
48 |
if ( isset($url[1]) ) {
|
49 |
-
|
|
|
50 |
$args['add_args'] = $query;
|
51 |
}
|
52 |
$args['format'] = $wp_rewrite->pagination_base.'/%#%';
|
53 |
$args['base'] = trailingslashit($url[0]).'%_%';
|
54 |
} else {
|
55 |
$big = 999999999;
|
56 |
-
$
|
|
|
|
|
57 |
}
|
|
|
58 |
$args['type'] = 'array';
|
59 |
$args['current'] = max(1, $paged);
|
60 |
$args['mid_size'] = max(9 - $args['current'], 3);
|
@@ -81,16 +85,10 @@ class Pagination {
|
|
81 |
|
82 |
// set next and prev using pages array generated by paginate links
|
83 |
if ( isset($current) && isset($this->pages[$current + 1]) ) {
|
84 |
-
$this->next = array('link' =>
|
85 |
-
if ( Pagination::is_search_query($this->next['link']) ) {
|
86 |
-
$this->next['link'] = untrailingslashit($this->next['link']);
|
87 |
-
}
|
88 |
}
|
89 |
if ( isset($current) && isset($this->pages[$current - 1]) ) {
|
90 |
-
$this->prev = array('link' =>
|
91 |
-
if ( Pagination::is_search_query($this->prev['link']) ) {
|
92 |
-
$this->prev['link'] = untrailingslashit($this->prev['link']);
|
93 |
-
}
|
94 |
}
|
95 |
if ( $paged < 2 ) {
|
96 |
$this->prev = '';
|
@@ -100,23 +98,6 @@ class Pagination {
|
|
100 |
}
|
101 |
}
|
102 |
|
103 |
-
/**
|
104 |
-
* Checks to see whether the given URL has a search query in it (s=*)
|
105 |
-
* @param string $url
|
106 |
-
* @return boolean
|
107 |
-
*/
|
108 |
-
public static function is_search_query( $url ) {
|
109 |
-
global $wp;
|
110 |
-
|
111 |
-
foreach( $wp->public_query_vars as $public_query_var ) {
|
112 |
-
if ( strpos($url, $public_query_var.'=') !== false ) {
|
113 |
-
return true;
|
114 |
-
}
|
115 |
-
}
|
116 |
-
|
117 |
-
return false;
|
118 |
-
}
|
119 |
-
|
120 |
/**
|
121 |
*
|
122 |
*
|
@@ -136,10 +117,13 @@ class Pagination {
|
|
136 |
'end_size' => 1,
|
137 |
'mid_size' => 2,
|
138 |
'type' => 'array',
|
139 |
-
'add_args' =>
|
140 |
'add_fragment' => ''
|
141 |
);
|
142 |
$args = wp_parse_args($args, $defaults);
|
|
|
|
|
|
|
143 |
// Who knows what else people pass in $args
|
144 |
$args['total'] = intval((int) $args['total']);
|
145 |
if ( $args['total'] < 2 ) {
|
@@ -164,11 +148,12 @@ class Pagination {
|
|
164 |
$dots = true;
|
165 |
} else {
|
166 |
if ( $args['show_all'] || ($n <= $args['end_size'] || ($args['current'] && $n >= $args['current'] - $args['mid_size'] && $n <= $args['current'] + $args['mid_size']) || $n > $args['total'] - $args['end_size']) ) {
|
167 |
-
|
|
|
168 |
$link = str_replace('%#%', $n, $link);
|
169 |
|
170 |
// we first follow the user trailing slash configuration
|
171 |
-
$link = user_trailingslashit($link);
|
172 |
|
173 |
// then we add all required querystring parameters
|
174 |
if ( $args['add_args'] ) {
|
@@ -178,7 +163,7 @@ class Pagination {
|
|
178 |
// last, we add fragment if needed
|
179 |
$link .= $args['add_fragment'];
|
180 |
|
181 |
-
$link =
|
182 |
|
183 |
$page_links[] = array(
|
184 |
'class' => 'page-number page-numbers',
|
@@ -200,6 +185,32 @@ class Pagination {
|
|
200 |
|
201 |
return $page_links;
|
202 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
}
|
205 |
|
44 |
|
45 |
$args['total'] = ceil($wp_query->found_posts / $ppp);
|
46 |
if ( $wp_rewrite->using_permalinks() ) {
|
47 |
+
$url = explode('?', get_pagenum_link(0, false));
|
48 |
if ( isset($url[1]) ) {
|
49 |
+
$query = array();
|
50 |
+
wp_parse_str($url[1], $query);
|
51 |
$args['add_args'] = $query;
|
52 |
}
|
53 |
$args['format'] = $wp_rewrite->pagination_base.'/%#%';
|
54 |
$args['base'] = trailingslashit($url[0]).'%_%';
|
55 |
} else {
|
56 |
$big = 999999999;
|
57 |
+
$pagination_link = get_pagenum_link($big, false);
|
58 |
+
$args['base'] = str_replace( 'paged='.$big, '', $pagination_link );
|
59 |
+
$args['format'] = '?paged=%#%';
|
60 |
}
|
61 |
+
|
62 |
$args['type'] = 'array';
|
63 |
$args['current'] = max(1, $paged);
|
64 |
$args['mid_size'] = max(9 - $args['current'], 3);
|
85 |
|
86 |
// set next and prev using pages array generated by paginate links
|
87 |
if ( isset($current) && isset($this->pages[$current + 1]) ) {
|
88 |
+
$this->next = array('link' => $this->pages[$current + 1]['link'], 'class' => 'page-numbers next');
|
|
|
|
|
|
|
89 |
}
|
90 |
if ( isset($current) && isset($this->pages[$current - 1]) ) {
|
91 |
+
$this->prev = array('link' => $this->pages[$current - 1]['link'], 'class' => 'page-numbers prev');
|
|
|
|
|
|
|
92 |
}
|
93 |
if ( $paged < 2 ) {
|
94 |
$this->prev = '';
|
98 |
}
|
99 |
}
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
/**
|
102 |
*
|
103 |
*
|
117 |
'end_size' => 1,
|
118 |
'mid_size' => 2,
|
119 |
'type' => 'array',
|
120 |
+
'add_args' => array(), // array of query args to add
|
121 |
'add_fragment' => ''
|
122 |
);
|
123 |
$args = wp_parse_args($args, $defaults);
|
124 |
+
|
125 |
+
$args = Pagination::sanitize_args($args);
|
126 |
+
|
127 |
// Who knows what else people pass in $args
|
128 |
$args['total'] = intval((int) $args['total']);
|
129 |
if ( $args['total'] < 2 ) {
|
148 |
$dots = true;
|
149 |
} else {
|
150 |
if ( $args['show_all'] || ($n <= $args['end_size'] || ($args['current'] && $n >= $args['current'] - $args['mid_size'] && $n <= $args['current'] + $args['mid_size']) || $n > $args['total'] - $args['end_size']) ) {
|
151 |
+
|
152 |
+
$link = str_replace('%_%', 1 == $n ? '' : $args['format'], $args['base'] );
|
153 |
$link = str_replace('%#%', $n, $link);
|
154 |
|
155 |
// we first follow the user trailing slash configuration
|
156 |
+
$link = URLHelper::user_trailingslashit( $link );
|
157 |
|
158 |
// then we add all required querystring parameters
|
159 |
if ( $args['add_args'] ) {
|
163 |
// last, we add fragment if needed
|
164 |
$link .= $args['add_fragment'];
|
165 |
|
166 |
+
$link = apply_filters('paginate_links', $link);
|
167 |
|
168 |
$page_links[] = array(
|
169 |
'class' => 'page-number page-numbers',
|
185 |
|
186 |
return $page_links;
|
187 |
}
|
188 |
+
|
189 |
+
protected static function sanitize_args( $args ) {
|
190 |
+
|
191 |
+
$format_args = array();
|
192 |
+
|
193 |
+
$format = explode( '?', str_replace( '%_%', $args['format'], $args['base'] ) );
|
194 |
+
$format_query = isset( $format[1] ) ? $format[1] : '';
|
195 |
+
|
196 |
+
wp_parse_str( $format_query, $format_args );
|
197 |
+
|
198 |
+
// Remove the format argument from the array of query arguments, to avoid overwriting custom format.
|
199 |
+
foreach ( $format_args as $format_arg => $format_arg_value ) {
|
200 |
+
unset( $args['add_args'][ $format_arg ] );
|
201 |
+
}
|
202 |
+
|
203 |
+
$url_parts = explode( '?', $args['base']);
|
204 |
+
if ( isset( $url_parts[1] ) ) {
|
205 |
+
// Find the query args of the requested URL.
|
206 |
+
$url_query_args = array();
|
207 |
+
wp_parse_str( $url_parts[1], $url_query_args );
|
208 |
|
209 |
+
$args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $url_query_args ));
|
210 |
+
$args['base'] = $url_parts[0] . '%_%';
|
211 |
+
}
|
212 |
+
|
213 |
+
return $args;
|
214 |
+
}
|
215 |
}
|
216 |
|
lib/Theme.php
CHANGED
@@ -50,6 +50,11 @@ class Theme extends Core {
|
|
50 |
public $slug;
|
51 |
public $uri;
|
52 |
|
|
|
|
|
|
|
|
|
|
|
53 |
/**
|
54 |
* Constructs a new TimberTheme object. NOTE the TimberTheme object of the current theme comes in the default `Timber::get_context()` call. You can access this in your twig template via `{{site.theme}}.
|
55 |
* @param string $slug
|
@@ -77,21 +82,14 @@ class Theme extends Core {
|
|
77 |
* @param string $slug
|
78 |
*/
|
79 |
protected function init( $slug = null ) {
|
80 |
-
$theme = wp_get_theme($slug);
|
81 |
-
$this->name = $theme->get('Name');
|
82 |
-
$
|
83 |
-
$this->slug = $ss;
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
$this->uri = get_stylesheet_directory_uri();
|
90 |
-
$this->parent_slug = $theme->get('Template');
|
91 |
-
if ( !$this->parent_slug ) {
|
92 |
-
$this->uri = get_template_directory_uri();
|
93 |
-
}
|
94 |
-
if ( $this->parent_slug && $this->parent_slug != $this->slug ) {
|
95 |
$this->parent = new Theme($this->parent_slug);
|
96 |
}
|
97 |
}
|
@@ -101,7 +99,7 @@ class Theme extends Core {
|
|
101 |
* @return string the absolute path to the theme (ex: `http://example.org/wp-content/themes/my-timber-theme`)
|
102 |
*/
|
103 |
public function link() {
|
104 |
-
return $this->
|
105 |
}
|
106 |
|
107 |
/**
|
@@ -129,3 +127,4 @@ class Theme extends Core {
|
|
129 |
}
|
130 |
|
131 |
}
|
|
50 |
public $slug;
|
51 |
public $uri;
|
52 |
|
53 |
+
/**
|
54 |
+
* @var WP_Theme the underlying WordPress native Theme object
|
55 |
+
*/
|
56 |
+
private $theme;
|
57 |
+
|
58 |
/**
|
59 |
* Constructs a new TimberTheme object. NOTE the TimberTheme object of the current theme comes in the default `Timber::get_context()` call. You can access this in your twig template via `{{site.theme}}.
|
60 |
* @param string $slug
|
82 |
* @param string $slug
|
83 |
*/
|
84 |
protected function init( $slug = null ) {
|
85 |
+
$this->theme = wp_get_theme($slug);
|
86 |
+
$this->name = $this->theme->get('Name');
|
87 |
+
$this->slug = $this->theme->get_stylesheet();
|
|
|
88 |
|
89 |
+
$this->uri = $this->theme->get_template_directory_uri();
|
90 |
+
|
91 |
+
if ( $this->theme->parent()) {
|
92 |
+
$this->parent_slug = $this->theme->parent()->get_stylesheet();
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
$this->parent = new Theme($this->parent_slug);
|
94 |
}
|
95 |
}
|
99 |
* @return string the absolute path to the theme (ex: `http://example.org/wp-content/themes/my-timber-theme`)
|
100 |
*/
|
101 |
public function link() {
|
102 |
+
return $this->theme->get_stylesheet_directory_uri();
|
103 |
}
|
104 |
|
105 |
/**
|
127 |
}
|
128 |
|
129 |
}
|
130 |
+
|
lib/Timber.php
CHANGED
@@ -35,7 +35,7 @@ use Timber\Loader;
|
|
35 |
*/
|
36 |
class Timber {
|
37 |
|
38 |
-
public static $version = '1.2.
|
39 |
public static $locations;
|
40 |
public static $dirname = 'views';
|
41 |
public static $twig_cache = false;
|
35 |
*/
|
36 |
class Timber {
|
37 |
|
38 |
+
public static $version = '1.2.1';
|
39 |
public static $locations;
|
40 |
public static $dirname = 'views';
|
41 |
public static $twig_cache = false;
|
lib/URLHelper.php
CHANGED
@@ -24,9 +24,8 @@ class URLHelper {
|
|
24 |
* Get url scheme
|
25 |
* @return string
|
26 |
*/
|
27 |
-
public static function get_scheme()
|
28 |
-
|
29 |
-
return isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
|
30 |
}
|
31 |
|
32 |
|
@@ -96,10 +95,10 @@ class URLHelper {
|
|
96 |
* @return string the HTTP_HOST or SERVER_NAME
|
97 |
*/
|
98 |
public static function get_host() {
|
99 |
-
if ( isset($_SERVER['HTTP_HOST']) ) {
|
100 |
return $_SERVER['HTTP_HOST'];
|
101 |
}
|
102 |
-
if ( isset($_SERVER['SERVER_NAME']) ) {
|
103 |
return $_SERVER['SERVER_NAME'];
|
104 |
}
|
105 |
return '';
|
@@ -291,6 +290,29 @@ class URLHelper {
|
|
291 |
return $link;
|
292 |
}
|
293 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
294 |
/**
|
295 |
* Returns the url parameters, for example for url http://example.org/blog/post/news/2014/whatever
|
296 |
* this will return array('blog', 'post', 'news', '2014', 'whatever');
|
24 |
* Get url scheme
|
25 |
* @return string
|
26 |
*/
|
27 |
+
public static function get_scheme() {
|
28 |
+
return isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
|
|
|
29 |
}
|
30 |
|
31 |
|
95 |
* @return string the HTTP_HOST or SERVER_NAME
|
96 |
*/
|
97 |
public static function get_host() {
|
98 |
+
if ( isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] ) {
|
99 |
return $_SERVER['HTTP_HOST'];
|
100 |
}
|
101 |
+
if ( isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME']) {
|
102 |
return $_SERVER['SERVER_NAME'];
|
103 |
}
|
104 |
return '';
|
290 |
return $link;
|
291 |
}
|
292 |
|
293 |
+
/**
|
294 |
+
* Pass links through user_trailingslashit handling query strings properly
|
295 |
+
*
|
296 |
+
* @param string $link
|
297 |
+
* @return string
|
298 |
+
* */
|
299 |
+
public static function user_trailingslashit( $link ) {
|
300 |
+
$link_parts = parse_url($link);
|
301 |
+
|
302 |
+
if ( !$link_parts ) {
|
303 |
+
return $link;
|
304 |
+
}
|
305 |
+
|
306 |
+
if( isset($link_parts['path']) && $link_parts['path'] != '/' ) {
|
307 |
+
$new_path = user_trailingslashit( $link_parts['path'] );
|
308 |
+
|
309 |
+
if ( $new_path != $link_parts['path'] ) {
|
310 |
+
$link = str_replace($link_parts['path'], $new_path, $link);
|
311 |
+
}
|
312 |
+
}
|
313 |
+
return $link;
|
314 |
+
}
|
315 |
+
|
316 |
/**
|
317 |
* Returns the url parameters, for example for url http://example.org/blog/post/news/2014/whatever
|
318 |
* this will return array('blog', 'post', 'news', '2014', 'whatever');
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: jarednova, connorjburton, lggorman
|
3 |
Tags: template engine, templates, twig
|
4 |
Requires at least: 3.7
|
5 |
-
Stable tag: 1.1
|
6 |
-
Tested up to: 4.
|
7 |
PHP version: 5.3.0 or greater
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
2 |
Contributors: jarednova, connorjburton, lggorman
|
3 |
Tags: template engine, templates, twig
|
4 |
Requires at least: 3.7
|
5 |
+
Stable tag: 1.2.1
|
6 |
+
Tested up to: 4.7.1
|
7 |
PHP version: 5.3.0 or greater
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
timber.php
CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Timber
|
|
4 |
Description: The WordPress Timber Library allows you to write themes using the power Twig templates.
|
5 |
Plugin URI: http://timber.upstatement.com
|
6 |
Author: Jared Novack + Upstatement
|
7 |
-
Version: 1.2.
|
8 |
Author URI: http://upstatement.com/
|
9 |
*/
|
10 |
// we look for Composer files first in the plugins dir.
|
4 |
Description: The WordPress Timber Library allows you to write themes using the power Twig templates.
|
5 |
Plugin URI: http://timber.upstatement.com
|
6 |
Author: Jared Novack + Upstatement
|
7 |
+
Version: 1.2.1
|
8 |
Author URI: http://upstatement.com/
|
9 |
*/
|
10 |
// we look for Composer files first in the plugins dir.
|