Timber - Version 1.1.10

Version Description

  • Added support for Co-Authors Plus Guest Authors #1239 (thanks @motia)
  • Fix for Yoast SEO with multisite #1244 (thanks @alexandernanberg)
  • Fixes issues with basedir restrictions that arose in Timber 1.1.9 #1245
Download this release

Release Info

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

Code changes from version 1.1.9 to 1.1.10

lib/Integrations/CoAuthorsPlus.php CHANGED
@@ -4,6 +4,8 @@ namespace Timber\Integrations;
4
 
5
  class CoAuthorsPlus {
6
 
 
 
7
  /**
8
  * @codeCoverageIgnore
9
  */
@@ -22,9 +24,36 @@ class CoAuthorsPlus {
22
  $authors = array();
23
  $cauthors = get_coauthors($post->ID);
24
  foreach ( $cauthors as $author ) {
25
- $authors[] = new \Timber\User($author);
 
 
 
 
 
26
  }
27
  return $authors;
28
  }
29
 
30
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  class CoAuthorsPlus {
6
 
7
+ public static $prefer_gravatar = false;
8
+
9
  /**
10
  * @codeCoverageIgnore
11
  */
24
  $authors = array();
25
  $cauthors = get_coauthors($post->ID);
26
  foreach ( $cauthors as $author ) {
27
+ $uid = $this->get_user_uid( $author );
28
+ if ( $uid ) {
29
+ $authors[] = new \Timber\User($uid);
30
+ } else {
31
+ $authors[] = new CoAuthorsPlusUser($author);
32
+ }
33
  }
34
  return $authors;
35
  }
36
 
37
+ /**
38
+ * return the user id for normal authors
39
+ * the user login for guest authors if it exists and self::prefer_users == true
40
+ * or null
41
+ * @internal
42
+ * @param object $cauthor
43
+ * @return int|string|null
44
+ */
45
+ protected function get_user_uid( $cauthor ) {
46
+ // if is guest author
47
+ if( is_object($cauthor) && isset($cauthor->type) && $cauthor->type == 'guest-author'){
48
+ // if have have a linked user account
49
+ global $coauthors_plus;
50
+ if( !$coauthors_plus->force_guest_authors && isset($cauthor->linked_account) && !empty($cauthor->linked_account ) ){
51
+ return $cauthor->linked_account;
52
+ } else {
53
+ return null;
54
+ }
55
+ } else {
56
+ return $cauthor->id;
57
+ }
58
+ }
59
+ }
lib/Integrations/CoAuthorsPlusUser.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Timber\Integrations;
4
+
5
+ class CoAuthorsPlusUser extends \Timber\User {
6
+
7
+ /**
8
+ * @param object $author co-author object
9
+ */
10
+ public function __construct( $author ) {
11
+ parent::__construct($author);
12
+ }
13
+
14
+ /**
15
+ * @internal
16
+ * @param false|object $coauthor co-author object
17
+ */
18
+ protected function init( $coauthor = false ) {
19
+ $this->id = $coauthor->ID;
20
+ $this->first_name = $coauthor->first_name;
21
+ $this->last_name = $coauthor->last_name;
22
+ $this->user_nicename = $coauthor->user_nicename;
23
+ $this->description = $coauthor->description;
24
+
25
+ /**
26
+ * @property string name
27
+ */
28
+ $this->display_name = $coauthor->display_name;
29
+ $this->_link = get_author_posts_url(null, $coauthor->user_nicename );
30
+
31
+ // 96 is the default wordpress avatar size
32
+ $avatar_url = get_the_post_thumbnail_url($this->id, 96);
33
+ if ( CoAuthorsPlus::$prefer_gravatar || !$avatar_url ) {
34
+ $avatar_url = get_avatar_url($coauthor->user_email);
35
+ }
36
+ if ( $avatar_url ) {
37
+ $this->avatar = new \Timber\Image($avatar_url);
38
+ }
39
+ }
40
+ }
lib/Loader.php CHANGED
@@ -122,9 +122,14 @@ class Loader {
122
  * @return \Twig_Loader_Filesystem
123
  */
124
  public function get_loader() {
125
- $paths = array_merge($this->locations, array(ini_get('open_basedir') ? ABSPATH : '/'));
 
126
  $paths = apply_filters('timber/loader/paths', $paths);
127
- $fs = new \Twig_Loader_Filesystem($paths, '/');
 
 
 
 
128
  return $fs;
129
  }
130
 
122
  * @return \Twig_Loader_Filesystem
123
  */
124
  public function get_loader() {
125
+ $open_basedir = ini_get('open_basedir');
126
+ $paths = array_merge($this->locations, array( $open_basedir ? ABSPATH : '/'));
127
  $paths = apply_filters('timber/loader/paths', $paths);
128
+ $rootPath = '/';
129
+ if ( $open_basedir ) {
130
+ $rootPath = null;
131
+ }
132
+ $fs = new \Twig_Loader_Filesystem($paths, $rootPath);
133
  return $fs;
134
  }
135
 
lib/Site.php CHANGED
@@ -96,7 +96,7 @@ class Site extends Core implements CoreInterface {
96
  public $rss;
97
  public $rss2;
98
  public $atom;
99
-
100
  /**
101
  * Constructs a TimberSite object
102
  * @example
@@ -111,33 +111,28 @@ class Site extends Core implements CoreInterface {
111
  */
112
  public function __construct( $site_name_or_id = null ) {
113
  if ( is_multisite() ) {
114
- $blog_ids = self::switch_to_blog($site_name_or_id);
 
 
 
 
115
  $this->init();
116
- $this->init_as_multisite($blog_ids['new']);
117
- return switch_to_blog($blog_ids['old']);
118
- }
119
- $this->init();
120
- $this->init_as_singlesite();
121
  }
122
 
123
  /**
124
  * Switches to the blog requested in the request
125
  * @param string|integer|null $site_name_or_id
126
- * @return array with the ID of the old and new blogs
127
  */
128
  protected static function switch_to_blog( $site_name_or_id ) {
129
  if ( $site_name_or_id === null ) {
130
- //this is necessary for some reason, otherwise returns 1 all the time
131
- if ( is_multisite() ) {
132
- restore_current_blog();
133
- $site_name_or_id = get_current_blog_id();
134
- }
135
  }
136
- /* we need to store the current blog, but switch things to the blog id of the Site object requested */
137
- $old_id = get_current_blog_id();
138
  $info = get_blog_details($site_name_or_id);
139
  switch_to_blog($info->blog_id);
140
- return array('old' => $old_id, 'new' => $info->blog_id);
141
  }
142
 
143
  /**
@@ -217,12 +212,12 @@ class Site extends Core implements CoreInterface {
217
 
218
  protected function icon_multisite( $site_id ) {
219
  $image = null;
220
- $blog_ids = self::switch_to_blog($site_id);
221
- $iid = get_blog_option($blog_ids['new'], 'site_icon');
222
  if ( $iid ) {
223
  $image = new Image($iid);
224
  }
225
- switch_to_blog($blog_ids['old']);
226
  return $image;
227
  }
228
 
96
  public $rss;
97
  public $rss2;
98
  public $atom;
99
+
100
  /**
101
  * Constructs a TimberSite object
102
  * @example
111
  */
112
  public function __construct( $site_name_or_id = null ) {
113
  if ( is_multisite() ) {
114
+ $blog_id = self::switch_to_blog($site_name_or_id);
115
+ $this->init();
116
+ $this->init_as_multisite($blog_id);
117
+ restore_current_blog();
118
+ } else {
119
  $this->init();
120
+ $this->init_as_singlesite();
121
+ }
 
 
 
122
  }
123
 
124
  /**
125
  * Switches to the blog requested in the request
126
  * @param string|integer|null $site_name_or_id
127
+ * @return integer with the ID of the new blog
128
  */
129
  protected static function switch_to_blog( $site_name_or_id ) {
130
  if ( $site_name_or_id === null ) {
131
+ $site_name_or_id = get_current_blog_id();
 
 
 
 
132
  }
 
 
133
  $info = get_blog_details($site_name_or_id);
134
  switch_to_blog($info->blog_id);
135
+ return $info->blog_id;
136
  }
137
 
138
  /**
212
 
213
  protected function icon_multisite( $site_id ) {
214
  $image = null;
215
+ $blog_id = self::switch_to_blog($site_id);
216
+ $iid = get_blog_option($blog_id, 'site_icon');
217
  if ( $iid ) {
218
  $image = new Image($iid);
219
  }
220
+ restore_current_blog();
221
  return $image;
222
  }
223
 
lib/Timber.php CHANGED
@@ -35,7 +35,7 @@ use Timber\Loader;
35
  */
36
  class Timber {
37
 
38
- public static $version = '1.1.9';
39
  public static $locations;
40
  public static $dirname = 'views';
41
  public static $twig_cache = false;
@@ -77,6 +77,9 @@ class Timber {
77
  }
78
  }
79
 
 
 
 
80
  private function backwards_compatibility() {
81
  if ( class_exists('TimberArchives') ) {
82
  //already run, so bail
@@ -310,12 +313,6 @@ class Timber {
310
  * @return bool|string
311
  */
312
  public static function fetch( $filenames, $data = array(), $expires = false, $cache_mode = Loader::CACHE_USE_DEFAULT ) {
313
- if ( $expires === true ) {
314
- //if this is reading as true; the user probably is using the old $echo param
315
- //so we should move all vars up by a spot
316
- $expires = $cache_mode;
317
- $cache_mode = Loader::CACHE_USE_DEFAULT;
318
- }
319
  $output = self::compile($filenames, $data, $expires, $cache_mode, true);
320
  $output = apply_filters('timber_compile_result', $output);
321
  return $output;
35
  */
36
  class Timber {
37
 
38
+ public static $version = '1.1.10';
39
  public static $locations;
40
  public static $dirname = 'views';
41
  public static $twig_cache = false;
77
  }
78
  }
79
 
80
+ /**
81
+ * @codeCoverageIgnore
82
+ */
83
  private function backwards_compatibility() {
84
  if ( class_exists('TimberArchives') ) {
85
  //already run, so bail
313
  * @return bool|string
314
  */
315
  public static function fetch( $filenames, $data = array(), $expires = false, $cache_mode = Loader::CACHE_USE_DEFAULT ) {
 
 
 
 
 
 
316
  $output = self::compile($filenames, $data, $expires, $cache_mode, true);
317
  $output = apply_filters('timber_compile_result', $output);
318
  return $output;
lib/User.php CHANGED
@@ -66,7 +66,7 @@ class User extends Core implements CoreInterface {
66
  public $user_nicename;
67
 
68
  /**
69
- * @param int|bool $uid
70
  */
71
  public function __construct( $uid = false ) {
72
  $this->init($uid);
@@ -117,7 +117,7 @@ class User extends Core implements CoreInterface {
117
 
118
  /**
119
  * @internal
120
- * @param int|bool $uid The user ID to use
121
  */
122
  protected function init( $uid = false ) {
123
  if ( $uid === false ) {
66
  public $user_nicename;
67
 
68
  /**
69
+ * @param object|int|bool $uid
70
  */
71
  public function __construct( $uid = false ) {
72
  $this->init($uid);
117
 
118
  /**
119
  * @internal
120
+ * @param object|int|bool $uid The user ID to use
121
  */
122
  protected function init( $uid = false ) {
123
  if ( $uid === false ) {
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: jarednova, connorjburton, lggorman
3
  Tags: template engine, templates, twig
4
  Requires at least: 3.7
5
- Stable tag: 1.1.9
6
  Tested up to: 4.6
7
  PHP version: 5.3.0 or greater
8
  License: GPLv2 or later
@@ -41,6 +41,11 @@ Timber is great for any WordPress developer who cares about writing good, mainta
41
 
42
  == Changelog ==
43
 
 
 
 
 
 
44
  = 1.1.9 =
45
  * Timber now retrieves native term meta info #824
46
  * Added site icon support in Theme #1210
@@ -48,7 +53,6 @@ Timber is great for any WordPress developer who cares about writing good, mainta
48
  * Fix to off-site image URLs! #1234 (thanks @njbarrett)
49
  * Fix inconsistency with Post::get_terms #1222 (thanks @haroldangenent)
50
 
51
-
52
  = 1.1.8 =
53
  * Fixed image generation when images are updated/deleted by WordPress (thanks @dudewithamood)
54
 
2
  Contributors: jarednova, connorjburton, lggorman
3
  Tags: template engine, templates, twig
4
  Requires at least: 3.7
5
+ Stable tag: 1.1.10
6
  Tested up to: 4.6
7
  PHP version: 5.3.0 or greater
8
  License: GPLv2 or later
41
 
42
  == Changelog ==
43
 
44
+ = 1.1.10 =
45
+ * Added support for Co-Authors Plus Guest Authors #1239 (thanks @motia)
46
+ * Fix for Yoast SEO with multisite #1244 (thanks @alexandernanberg)
47
+ * Fixes issues with basedir restrictions that arose in Timber 1.1.9 #1245
48
+
49
  = 1.1.9 =
50
  * Timber now retrieves native term meta info #824
51
  * Added site icon support in Theme #1210
53
  * Fix to off-site image URLs! #1234 (thanks @njbarrett)
54
  * Fix inconsistency with Post::get_terms #1222 (thanks @haroldangenent)
55
 
 
56
  = 1.1.8 =
57
  * Fixed image generation when images are updated/deleted by WordPress (thanks @dudewithamood)
58
 
timber.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Timber
4
  Description: The WordPress Timber Library allows you to write themes using the power Twig templates.
5
  Plugin URI: http://timber.upstatement.com
6
  Author: Jared Novack + Upstatement
7
- Version: 1.1.9
8
  Author URI: http://upstatement.com/
9
  */
10
  // we look for Composer files first in the plugins dir.
4
  Description: The WordPress Timber Library allows you to write themes using the power Twig templates.
5
  Plugin URI: http://timber.upstatement.com
6
  Author: Jared Novack + Upstatement
7
+ Version: 1.1.10
8
  Author URI: http://upstatement.com/
9
  */
10
  // we look for Composer files first in the plugins dir.
vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once __DIR__ . '/composer' . '/autoload_real.php';
6
 
7
- return ComposerAutoloaderInit05219471bb425701949f68630de707ca::getLoader();
4
 
5
  require_once __DIR__ . '/composer' . '/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInitcf447073f6657b2ba7aa1f473b8d19ac::getLoader();
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInit05219471bb425701949f68630de707ca
6
  {
7
  private static $loader;
8
 
@@ -19,9 +19,9 @@ class ComposerAutoloaderInit05219471bb425701949f68630de707ca
19
  return self::$loader;
20
  }
21
 
22
- spl_autoload_register(array('ComposerAutoloaderInit05219471bb425701949f68630de707ca', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
- spl_autoload_unregister(array('ComposerAutoloaderInit05219471bb425701949f68630de707ca', 'loadClassLoader'));
25
 
26
  $map = require __DIR__ . '/autoload_namespaces.php';
27
  foreach ($map as $namespace => $path) {
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
+ class ComposerAutoloaderInitcf447073f6657b2ba7aa1f473b8d19ac
6
  {
7
  private static $loader;
8
 
19
  return self::$loader;
20
  }
21
 
22
+ spl_autoload_register(array('ComposerAutoloaderInitcf447073f6657b2ba7aa1f473b8d19ac', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
+ spl_autoload_unregister(array('ComposerAutoloaderInitcf447073f6657b2ba7aa1f473b8d19ac', 'loadClassLoader'));
25
 
26
  $map = require __DIR__ . '/autoload_namespaces.php';
27
  foreach ($map as $namespace => $path) {