@@ -4,6 +4,6 @@ |
||
4 | 4 | |
5 | 5 | interface TimberKeyGeneratorInterface { |
6 | 6 | |
7 | - public function _get_cache_key(); |
|
7 | + public function _get_cache_key(); |
|
8 | 8 | |
9 | 9 | } |
@@ -6,25 +6,25 @@ |
||
6 | 6 | |
7 | 7 | class KeyGenerator implements KeyGeneratorInterface { |
8 | 8 | |
9 | - /** |
|
10 | - * @param mixed $value |
|
11 | - * @return string |
|
12 | - */ |
|
13 | - public function generateKey($value) { |
|
14 | - if (is_a($value, 'TimberKeyGeneratorInterface')) { |
|
15 | - return $value->_get_cache_key(); |
|
16 | - } |
|
17 | - |
|
18 | - if (is_array($value) && isset($value['_cache_key'])) { |
|
19 | - return $value['_cache_key']; |
|
20 | - } |
|
21 | - |
|
22 | - $key = md5(json_encode($value)); |
|
23 | - if (is_object($value)) { |
|
24 | - $key = get_class($value) . '|' . $key; |
|
25 | - } |
|
26 | - |
|
27 | - return $key; |
|
28 | - } |
|
9 | + /** |
|
10 | + * @param mixed $value |
|
11 | + * @return string |
|
12 | + */ |
|
13 | + public function generateKey($value) { |
|
14 | + if (is_a($value, 'TimberKeyGeneratorInterface')) { |
|
15 | + return $value->_get_cache_key(); |
|
16 | + } |
|
17 | + |
|
18 | + if (is_array($value) && isset($value['_cache_key'])) { |
|
19 | + return $value['_cache_key']; |
|
20 | + } |
|
21 | + |
|
22 | + $key = md5(json_encode($value)); |
|
23 | + if (is_object($value)) { |
|
24 | + $key = get_class($value) . '|' . $key; |
|
25 | + } |
|
26 | + |
|
27 | + return $key; |
|
28 | + } |
|
29 | 29 | |
30 | 30 | } |
@@ -2,306 +2,306 @@ |
||
2 | 2 | |
3 | 3 | class TimberMenuItem extends TimberCore implements TimberCoreInterface { |
4 | 4 | |
5 | - public $children; |
|
6 | - public $has_child_class = false; |
|
7 | - public $classes = array(); |
|
8 | - public $class = ''; |
|
9 | - public $level = 0; |
|
10 | - public $post_name; |
|
11 | - public $type; |
|
12 | - public $url; |
|
5 | + public $children; |
|
6 | + public $has_child_class = false; |
|
7 | + public $classes = array(); |
|
8 | + public $class = ''; |
|
9 | + public $level = 0; |
|
10 | + public $post_name; |
|
11 | + public $type; |
|
12 | + public $url; |
|
13 | 13 | |
14 | - public $PostClass = 'TimberPost'; |
|
14 | + public $PostClass = 'TimberPost'; |
|
15 | 15 | |
16 | - protected $_name; |
|
17 | - protected $_menu_item_object_id; |
|
18 | - protected $_menu_item_url; |
|
19 | - protected $menu_object; |
|
20 | - protected $master_object; |
|
16 | + protected $_name; |
|
17 | + protected $_menu_item_object_id; |
|
18 | + protected $_menu_item_url; |
|
19 | + protected $menu_object; |
|
20 | + protected $master_object; |
|
21 | 21 | |
22 | - /** |
|
23 | - * |
|
24 | - * |
|
25 | - * @param array|object $data |
|
26 | - */ |
|
27 | - public function __construct( $data ) { |
|
28 | - $data = (object) $data; |
|
29 | - $this->import( $data ); |
|
30 | - $this->import_classes( $data ); |
|
31 | - if ( isset( $this->name ) ) { |
|
32 | - $this->_name = $this->name; |
|
33 | - } |
|
34 | - $this->name = $this->name(); |
|
35 | - $this->add_class( 'menu-item-' . $this->ID ); |
|
36 | - $this->menu_object = $data; |
|
37 | - } |
|
22 | + /** |
|
23 | + * |
|
24 | + * |
|
25 | + * @param array|object $data |
|
26 | + */ |
|
27 | + public function __construct( $data ) { |
|
28 | + $data = (object) $data; |
|
29 | + $this->import( $data ); |
|
30 | + $this->import_classes( $data ); |
|
31 | + if ( isset( $this->name ) ) { |
|
32 | + $this->_name = $this->name; |
|
33 | + } |
|
34 | + $this->name = $this->name(); |
|
35 | + $this->add_class( 'menu-item-' . $this->ID ); |
|
36 | + $this->menu_object = $data; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return string the label for the menu item |
|
41 | - */ |
|
42 | - public function __toString() { |
|
43 | - return $this->name(); |
|
44 | - } |
|
39 | + /** |
|
40 | + * @return string the label for the menu item |
|
41 | + */ |
|
42 | + public function __toString() { |
|
43 | + return $this->name(); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * add a class the menu item should have |
|
48 | - * @param string $class_name to be added |
|
49 | - */ |
|
50 | - public function add_class( $class_name ) { |
|
51 | - $this->classes[] = $class_name; |
|
52 | - $this->class .= ' ' . $class_name; |
|
53 | - } |
|
46 | + /** |
|
47 | + * add a class the menu item should have |
|
48 | + * @param string $class_name to be added |
|
49 | + */ |
|
50 | + public function add_class( $class_name ) { |
|
51 | + $this->classes[] = $class_name; |
|
52 | + $this->class .= ' ' . $class_name; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * The label for the menu item |
|
57 | - * @api |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public function name() { |
|
61 | - if ( $title = $this->title() ) { |
|
62 | - return $title; |
|
63 | - } |
|
64 | - if ( isset( $this->_name ) ) { |
|
65 | - return $this->_name; |
|
66 | - } |
|
67 | - return ''; |
|
68 | - } |
|
55 | + /** |
|
56 | + * The label for the menu item |
|
57 | + * @api |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public function name() { |
|
61 | + if ( $title = $this->title() ) { |
|
62 | + return $title; |
|
63 | + } |
|
64 | + if ( isset( $this->_name ) ) { |
|
65 | + return $this->_name; |
|
66 | + } |
|
67 | + return ''; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * The slug for the menu item |
|
72 | - * @api |
|
73 | - * @example |
|
74 | - * ```twig |
|
75 | - * <ul> |
|
76 | - * {% for item in menu.items %} |
|
77 | - * <li class="{{item.slug}}"> |
|
78 | - * <a href="{{item.link}}">{{item.name}}</a> |
|
79 | - * </li> |
|
80 | - * {% endfor %} |
|
81 | - * </ul> |
|
82 | - * @return string the slug of the menu item kinda-like-this |
|
83 | - */ |
|
84 | - public function slug() { |
|
85 | - if ( !isset( $this->master_object ) ) { |
|
86 | - $this->master_object = $this->get_master_object(); |
|
87 | - } |
|
88 | - if ( isset( $this->master_object->post_name ) && $this->master_object->post_name ) { |
|
89 | - return $this->master_object->post_name; |
|
90 | - } |
|
91 | - return $this->post_name; |
|
92 | - } |
|
70 | + /** |
|
71 | + * The slug for the menu item |
|
72 | + * @api |
|
73 | + * @example |
|
74 | + * ```twig |
|
75 | + * <ul> |
|
76 | + * {% for item in menu.items %} |
|
77 | + * <li class="{{item.slug}}"> |
|
78 | + * <a href="{{item.link}}">{{item.name}}</a> |
|
79 | + * </li> |
|
80 | + * {% endfor %} |
|
81 | + * </ul> |
|
82 | + * @return string the slug of the menu item kinda-like-this |
|
83 | + */ |
|
84 | + public function slug() { |
|
85 | + if ( !isset( $this->master_object ) ) { |
|
86 | + $this->master_object = $this->get_master_object(); |
|
87 | + } |
|
88 | + if ( isset( $this->master_object->post_name ) && $this->master_object->post_name ) { |
|
89 | + return $this->master_object->post_name; |
|
90 | + } |
|
91 | + return $this->post_name; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @internal |
|
96 | - * @return mixed whatever object (Post, Term, etc.) the menu item represents |
|
97 | - */ |
|
98 | - protected function get_master_object() { |
|
99 | - if ( isset( $this->_menu_item_object_id ) ) { |
|
100 | - return new $this->PostClass( $this->_menu_item_object_id ); |
|
101 | - } |
|
102 | - } |
|
94 | + /** |
|
95 | + * @internal |
|
96 | + * @return mixed whatever object (Post, Term, etc.) the menu item represents |
|
97 | + */ |
|
98 | + protected function get_master_object() { |
|
99 | + if ( isset( $this->_menu_item_object_id ) ) { |
|
100 | + return new $this->PostClass( $this->_menu_item_object_id ); |
|
101 | + } |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @internal |
|
106 | - * @see TimberMenuItem::link |
|
107 | - * @return string an absolute URL http://example.org/my-page |
|
108 | - */ |
|
109 | - function get_link() { |
|
110 | - if ( !isset( $this->url ) || !$this->url ) { |
|
111 | - if ( isset( $this->_menu_item_type ) && $this->_menu_item_type == 'custom' ) { |
|
112 | - $this->url = $this->_menu_item_url; |
|
113 | - } else if ( isset( $this->menu_object ) && method_exists( $this->menu_object, 'get_link' ) ) { |
|
114 | - $this->url = $this->menu_object->get_link(); |
|
115 | - } |
|
116 | - } |
|
117 | - return $this->url; |
|
118 | - } |
|
104 | + /** |
|
105 | + * @internal |
|
106 | + * @see TimberMenuItem::link |
|
107 | + * @return string an absolute URL http://example.org/my-page |
|
108 | + */ |
|
109 | + function get_link() { |
|
110 | + if ( !isset( $this->url ) || !$this->url ) { |
|
111 | + if ( isset( $this->_menu_item_type ) && $this->_menu_item_type == 'custom' ) { |
|
112 | + $this->url = $this->_menu_item_url; |
|
113 | + } else if ( isset( $this->menu_object ) && method_exists( $this->menu_object, 'get_link' ) ) { |
|
114 | + $this->url = $this->menu_object->get_link(); |
|
115 | + } |
|
116 | + } |
|
117 | + return $this->url; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @internal |
|
122 | - * @see TimberMenuItem::path() |
|
123 | - * @return string a relative url /my-page |
|
124 | - */ |
|
125 | - function get_path() { |
|
126 | - return TimberURLHelper::get_rel_url( $this->get_link() ); |
|
127 | - } |
|
120 | + /** |
|
121 | + * @internal |
|
122 | + * @see TimberMenuItem::path() |
|
123 | + * @return string a relative url /my-page |
|
124 | + */ |
|
125 | + function get_path() { |
|
126 | + return TimberURLHelper::get_rel_url( $this->get_link() ); |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * |
|
131 | - * |
|
132 | - * @param TimberMenuItem $item |
|
133 | - */ |
|
134 | - function add_child( $item ) { |
|
135 | - if ( !$this->has_child_class ) { |
|
136 | - $this->add_class( 'menu-item-has-children' ); |
|
137 | - $this->has_child_class = true; |
|
138 | - } |
|
139 | - if ( !isset( $this->children ) ) { |
|
140 | - $this->children = array(); |
|
141 | - } |
|
142 | - $this->children[] = $item; |
|
143 | - $item->level = $this->level + 1; |
|
144 | - if ($item->children) { |
|
145 | - $this->update_child_levels(); |
|
146 | - } |
|
147 | - } |
|
129 | + /** |
|
130 | + * |
|
131 | + * |
|
132 | + * @param TimberMenuItem $item |
|
133 | + */ |
|
134 | + function add_child( $item ) { |
|
135 | + if ( !$this->has_child_class ) { |
|
136 | + $this->add_class( 'menu-item-has-children' ); |
|
137 | + $this->has_child_class = true; |
|
138 | + } |
|
139 | + if ( !isset( $this->children ) ) { |
|
140 | + $this->children = array(); |
|
141 | + } |
|
142 | + $this->children[] = $item; |
|
143 | + $item->level = $this->level + 1; |
|
144 | + if ($item->children) { |
|
145 | + $this->update_child_levels(); |
|
146 | + } |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * |
|
151 | - * @internal |
|
152 | - * @return bool |
|
153 | - */ |
|
154 | - function update_child_levels() { |
|
155 | - if (is_array($this->children)) { |
|
156 | - foreach( $this->children as $child ) { |
|
157 | - $child->level = $this->level + 1; |
|
158 | - $child->update_child_levels(); |
|
159 | - } |
|
160 | - return true; |
|
161 | - } |
|
162 | - } |
|
149 | + /** |
|
150 | + * |
|
151 | + * @internal |
|
152 | + * @return bool |
|
153 | + */ |
|
154 | + function update_child_levels() { |
|
155 | + if (is_array($this->children)) { |
|
156 | + foreach( $this->children as $child ) { |
|
157 | + $child->level = $this->level + 1; |
|
158 | + $child->update_child_levels(); |
|
159 | + } |
|
160 | + return true; |
|
161 | + } |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
165 | - * Imports the classes to be used in CSS |
|
166 | - * @internal |
|
167 | - * @param array|object $data |
|
168 | - */ |
|
169 | - function import_classes( $data ) { |
|
170 | - if ( is_array($data) ) { |
|
171 | - $data = (object) $data; |
|
172 | - } |
|
173 | - $this->classes = array_merge( $this->classes, $data->classes ); |
|
174 | - $this->classes = array_unique( $this->classes ); |
|
175 | - $this->classes = apply_filters( 'nav_menu_css_class', $this->classes, $this ); |
|
176 | - $this->class = trim( implode( ' ', $this->classes ) ); |
|
177 | - } |
|
164 | + /** |
|
165 | + * Imports the classes to be used in CSS |
|
166 | + * @internal |
|
167 | + * @param array|object $data |
|
168 | + */ |
|
169 | + function import_classes( $data ) { |
|
170 | + if ( is_array($data) ) { |
|
171 | + $data = (object) $data; |
|
172 | + } |
|
173 | + $this->classes = array_merge( $this->classes, $data->classes ); |
|
174 | + $this->classes = array_unique( $this->classes ); |
|
175 | + $this->classes = apply_filters( 'nav_menu_css_class', $this->classes, $this ); |
|
176 | + $this->class = trim( implode( ' ', $this->classes ) ); |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * |
|
181 | - * @internal |
|
182 | - * @return array|bool |
|
183 | - */ |
|
184 | - function get_children() { |
|
185 | - if ( isset( $this->children ) ) { |
|
186 | - return $this->children; |
|
187 | - } |
|
188 | - return false; |
|
189 | - } |
|
179 | + /** |
|
180 | + * |
|
181 | + * @internal |
|
182 | + * @return array|bool |
|
183 | + */ |
|
184 | + function get_children() { |
|
185 | + if ( isset( $this->children ) ) { |
|
186 | + return $this->children; |
|
187 | + } |
|
188 | + return false; |
|
189 | + } |
|
190 | 190 | |
191 | - /** |
|
192 | - * Checks to see if the menu item is an external link so if my site is `example.org`, `google.com/whatever` is an external link. Helpful when creating rules for the target of a link |
|
193 | - * @api |
|
194 | - * @example |
|
195 | - * ```twig |
|
196 | - * <a href="{{ item.link }}" target="{{ item.is_external ? '_blank' : '_self' }}"> |
|
197 | - * ``` |
|
198 | - * @return bool |
|
199 | - */ |
|
200 | - function is_external() { |
|
201 | - if ( $this->type != 'custom' ) { |
|
202 | - return false; |
|
203 | - } |
|
204 | - return TimberURLHelper::is_external( $this->url ); |
|
205 | - } |
|
191 | + /** |
|
192 | + * Checks to see if the menu item is an external link so if my site is `example.org`, `google.com/whatever` is an external link. Helpful when creating rules for the target of a link |
|
193 | + * @api |
|
194 | + * @example |
|
195 | + * ```twig |
|
196 | + * <a href="{{ item.link }}" target="{{ item.is_external ? '_blank' : '_self' }}"> |
|
197 | + * ``` |
|
198 | + * @return bool |
|
199 | + */ |
|
200 | + function is_external() { |
|
201 | + if ( $this->type != 'custom' ) { |
|
202 | + return false; |
|
203 | + } |
|
204 | + return TimberURLHelper::is_external( $this->url ); |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * @param string $key lookup key |
|
209 | - * @return mixed whatever value is storied in the database |
|
210 | - */ |
|
211 | - public function meta( $key ) { |
|
212 | - if ( is_object( $this->menu_object ) && method_exists( $this->menu_object, 'meta' ) ) { |
|
213 | - return $this->menu_object->meta( $key ); |
|
214 | - } |
|
215 | - if ( isset( $this->$key ) ) { |
|
216 | - return $this->$key; |
|
217 | - } |
|
218 | - } |
|
207 | + /** |
|
208 | + * @param string $key lookup key |
|
209 | + * @return mixed whatever value is storied in the database |
|
210 | + */ |
|
211 | + public function meta( $key ) { |
|
212 | + if ( is_object( $this->menu_object ) && method_exists( $this->menu_object, 'meta' ) ) { |
|
213 | + return $this->menu_object->meta( $key ); |
|
214 | + } |
|
215 | + if ( isset( $this->$key ) ) { |
|
216 | + return $this->$key; |
|
217 | + } |
|
218 | + } |
|
219 | 219 | |
220 | - /* Aliases */ |
|
220 | + /* Aliases */ |
|
221 | 221 | |
222 | - /** |
|
223 | - * Get the child [TimberMenuItems](#TimberMenuItem)s of a [TimberMenuItem](#TimberMenuItem) |
|
224 | - * @api |
|
225 | - * @return array|bool |
|
226 | - */ |
|
227 | - public function children() { |
|
228 | - return $this->get_children(); |
|
229 | - } |
|
222 | + /** |
|
223 | + * Get the child [TimberMenuItems](#TimberMenuItem)s of a [TimberMenuItem](#TimberMenuItem) |
|
224 | + * @api |
|
225 | + * @return array|bool |
|
226 | + */ |
|
227 | + public function children() { |
|
228 | + return $this->get_children(); |
|
229 | + } |
|
230 | 230 | |
231 | - /** |
|
232 | - * Checks to see if a link is external, helpful when creating rules for the target of a link |
|
233 | - * @see TimberMenuItem::is_external |
|
234 | - * @return bool |
|
235 | - */ |
|
236 | - public function external() { |
|
237 | - return $this->is_external(); |
|
238 | - } |
|
231 | + /** |
|
232 | + * Checks to see if a link is external, helpful when creating rules for the target of a link |
|
233 | + * @see TimberMenuItem::is_external |
|
234 | + * @return bool |
|
235 | + */ |
|
236 | + public function external() { |
|
237 | + return $this->is_external(); |
|
238 | + } |
|
239 | 239 | |
240 | - /** |
|
241 | - * Get the full link to a Menu Item |
|
242 | - * @api |
|
243 | - * @example |
|
244 | - * ```twig |
|
245 | - * {% for item in menu.items %} |
|
246 | - * <li><a href="{{ item.link }}">{{ item.title }}</a></li> |
|
247 | - * {% endfor %} |
|
248 | - * ``` |
|
249 | - * @return string a full URL like http://mysite.com/thing/ |
|
250 | - */ |
|
251 | - public function link() { |
|
252 | - return $this->get_link(); |
|
253 | - } |
|
240 | + /** |
|
241 | + * Get the full link to a Menu Item |
|
242 | + * @api |
|
243 | + * @example |
|
244 | + * ```twig |
|
245 | + * {% for item in menu.items %} |
|
246 | + * <li><a href="{{ item.link }}">{{ item.title }}</a></li> |
|
247 | + * {% endfor %} |
|
248 | + * ``` |
|
249 | + * @return string a full URL like http://mysite.com/thing/ |
|
250 | + */ |
|
251 | + public function link() { |
|
252 | + return $this->get_link(); |
|
253 | + } |
|
254 | 254 | |
255 | - /** |
|
256 | - * Return the relative path of a Menu Item's link |
|
257 | - * @example |
|
258 | - * ```twig |
|
259 | - * {% for item in menu.items %} |
|
260 | - * <li><a href="{{ item.path }}">{{ item.title }}</a></li> |
|
261 | - * {% endfor %} |
|
262 | - * ``` |
|
263 | - * @see get_path() |
|
264 | - * @return string the path of a URL like /foo |
|
265 | - */ |
|
266 | - public function path() { |
|
267 | - return $this->get_path(); |
|
268 | - } |
|
255 | + /** |
|
256 | + * Return the relative path of a Menu Item's link |
|
257 | + * @example |
|
258 | + * ```twig |
|
259 | + * {% for item in menu.items %} |
|
260 | + * <li><a href="{{ item.path }}">{{ item.title }}</a></li> |
|
261 | + * {% endfor %} |
|
262 | + * ``` |
|
263 | + * @see get_path() |
|
264 | + * @return string the path of a URL like /foo |
|
265 | + */ |
|
266 | + public function path() { |
|
267 | + return $this->get_path(); |
|
268 | + } |
|
269 | 269 | |
270 | - /** |
|
271 | - * Gets the link a menu item points at |
|
272 | - * @internal |
|
273 | - * @deprecated since 0.21.7 use link instead |
|
274 | - * @see link() |
|
275 | - * @return string a full URL like http://mysite.com/thing/ |
|
276 | - */ |
|
277 | - public function permalink() { |
|
278 | - return $this->get_link(); |
|
279 | - } |
|
270 | + /** |
|
271 | + * Gets the link a menu item points at |
|
272 | + * @internal |
|
273 | + * @deprecated since 0.21.7 use link instead |
|
274 | + * @see link() |
|
275 | + * @return string a full URL like http://mysite.com/thing/ |
|
276 | + */ |
|
277 | + public function permalink() { |
|
278 | + return $this->get_link(); |
|
279 | + } |
|
280 | 280 | |
281 | - /** |
|
282 | - * @internal |
|
283 | - * @deprecated since 0.21.7, use link instead |
|
284 | - * @see link() |
|
285 | - * @return string a full URL like http://mysite.com/thing/ |
|
286 | - */ |
|
287 | - public function get_permalink() { |
|
288 | - return $this->get_link(); |
|
289 | - } |
|
281 | + /** |
|
282 | + * @internal |
|
283 | + * @deprecated since 0.21.7, use link instead |
|
284 | + * @see link() |
|
285 | + * @return string a full URL like http://mysite.com/thing/ |
|
286 | + */ |
|
287 | + public function get_permalink() { |
|
288 | + return $this->get_link(); |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
292 | - * Gets the public label for the menu item |
|
293 | - * @example |
|
294 | - * ```twig |
|
295 | - * {% for item in menu.items %} |
|
296 | - * <li><a href="{{ item.link }}">{{ item.title }}</a></li> |
|
297 | - * {% endfor %} |
|
298 | - * ``` |
|
299 | - * @return string the public label like Foo |
|
300 | - */ |
|
301 | - public function title() { |
|
302 | - if ( isset( $this->__title ) ) { |
|
303 | - return $this->__title; |
|
304 | - } |
|
305 | - } |
|
291 | + /** |
|
292 | + * Gets the public label for the menu item |
|
293 | + * @example |
|
294 | + * ```twig |
|
295 | + * {% for item in menu.items %} |
|
296 | + * <li><a href="{{ item.link }}">{{ item.title }}</a></li> |
|
297 | + * {% endfor %} |
|
298 | + * ``` |
|
299 | + * @return string the public label like Foo |
|
300 | + */ |
|
301 | + public function title() { |
|
302 | + if ( isset( $this->__title ) ) { |
|
303 | + return $this->__title; |
|
304 | + } |
|
305 | + } |
|
306 | 306 | |
307 | 307 | } |
@@ -19,107 +19,107 @@ |
||
19 | 19 | */ |
20 | 20 | class TimberTheme extends TimberCore { |
21 | 21 | |
22 | - /** |
|
23 | - * @api |
|
24 | - * @var string the human-friendly name of the theme (ex: `My Timber Starter Theme`) |
|
25 | - */ |
|
26 | - public $name; |
|
22 | + /** |
|
23 | + * @api |
|
24 | + * @var string the human-friendly name of the theme (ex: `My Timber Starter Theme`) |
|
25 | + */ |
|
26 | + public $name; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @api |
|
30 | - * @var TimberTheme|bool the TimberTheme object for the parent theme (if it exists), false otherwise |
|
31 | - */ |
|
32 | - public $parent = false; |
|
28 | + /** |
|
29 | + * @api |
|
30 | + * @var TimberTheme|bool the TimberTheme object for the parent theme (if it exists), false otherwise |
|
31 | + */ |
|
32 | + public $parent = false; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @api |
|
36 | - * @var string the slug of the parent theme (ex: `_s`) |
|
37 | - */ |
|
38 | - public $parent_slug; |
|
34 | + /** |
|
35 | + * @api |
|
36 | + * @var string the slug of the parent theme (ex: `_s`) |
|
37 | + */ |
|
38 | + public $parent_slug; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @api |
|
42 | - * @var string the slug of the theme (ex: `my-super-theme`) |
|
43 | - */ |
|
44 | - public $slug; |
|
45 | - public $uri; |
|
40 | + /** |
|
41 | + * @api |
|
42 | + * @var string the slug of the theme (ex: `my-super-theme`) |
|
43 | + */ |
|
44 | + public $slug; |
|
45 | + public $uri; |
|
46 | 46 | |
47 | - /** |
|
48 | - * 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}}. |
|
49 | - * @param string $slug |
|
50 | - * @example |
|
51 | - * ```php |
|
52 | - * <?php |
|
53 | - * $theme = new TimberTheme("my-theme"); |
|
54 | - * $context['theme_stuff'] = $theme; |
|
55 | - * Timber::render('single.') |
|
56 | - * ?> |
|
57 | - * ``` |
|
58 | - * ```twig |
|
59 | - * We are currently using the {{ theme_stuff.name }} theme. |
|
60 | - * ``` |
|
61 | - * ```html |
|
62 | - * We are currently using the My Theme theme. |
|
63 | - * ``` |
|
64 | - */ |
|
65 | - function __construct($slug = null) { |
|
66 | - $this->init($slug); |
|
67 | - } |
|
47 | + /** |
|
48 | + * 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}}. |
|
49 | + * @param string $slug |
|
50 | + * @example |
|
51 | + * ```php |
|
52 | + * <?php |
|
53 | + * $theme = new TimberTheme("my-theme"); |
|
54 | + * $context['theme_stuff'] = $theme; |
|
55 | + * Timber::render('single.') |
|
56 | + * ?> |
|
57 | + * ``` |
|
58 | + * ```twig |
|
59 | + * We are currently using the {{ theme_stuff.name }} theme. |
|
60 | + * ``` |
|
61 | + * ```html |
|
62 | + * We are currently using the My Theme theme. |
|
63 | + * ``` |
|
64 | + */ |
|
65 | + function __construct($slug = null) { |
|
66 | + $this->init($slug); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @internal |
|
71 | - * @param string $slug |
|
72 | - */ |
|
73 | - protected function init($slug = null) { |
|
74 | - $data = wp_get_theme($slug); |
|
75 | - $this->name = $data->get('Name'); |
|
76 | - $ss = $data->get_stylesheet(); |
|
77 | - $this->slug = $ss; |
|
69 | + /** |
|
70 | + * @internal |
|
71 | + * @param string $slug |
|
72 | + */ |
|
73 | + protected function init($slug = null) { |
|
74 | + $data = wp_get_theme($slug); |
|
75 | + $this->name = $data->get('Name'); |
|
76 | + $ss = $data->get_stylesheet(); |
|
77 | + $this->slug = $ss; |
|
78 | 78 | |
79 | - if ( ! function_exists( 'get_home_path' ) ) { |
|
80 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
81 | - } |
|
79 | + if ( ! function_exists( 'get_home_path' ) ) { |
|
80 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
81 | + } |
|
82 | 82 | |
83 | - $this->uri = get_stylesheet_directory_uri(); |
|
84 | - $this->parent_slug = $data->get('Template'); |
|
85 | - if ( !$this->parent_slug ) { |
|
86 | - $this->uri = get_template_directory_uri(); |
|
87 | - } |
|
88 | - if ( $this->parent_slug && $this->parent_slug != $this->slug ) { |
|
89 | - $this->parent = new TimberTheme($this->parent_slug); |
|
90 | - } |
|
91 | - } |
|
83 | + $this->uri = get_stylesheet_directory_uri(); |
|
84 | + $this->parent_slug = $data->get('Template'); |
|
85 | + if ( !$this->parent_slug ) { |
|
86 | + $this->uri = get_template_directory_uri(); |
|
87 | + } |
|
88 | + if ( $this->parent_slug && $this->parent_slug != $this->slug ) { |
|
89 | + $this->parent = new TimberTheme($this->parent_slug); |
|
90 | + } |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @api |
|
95 | - * @return string the absolute path to the theme (ex: `http://example.org/wp-content/themes/my-timber-theme`) |
|
96 | - */ |
|
97 | - public function link() { |
|
98 | - return $this->uri; |
|
99 | - } |
|
93 | + /** |
|
94 | + * @api |
|
95 | + * @return string the absolute path to the theme (ex: `http://example.org/wp-content/themes/my-timber-theme`) |
|
96 | + */ |
|
97 | + public function link() { |
|
98 | + return $this->uri; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @api |
|
103 | - * @return string the relative path to the theme (ex: `/wp-content/themes/my-timber-theme`) |
|
104 | - */ |
|
105 | - public function path() { |
|
106 | - return TimberURLHelper::get_rel_url( $this->link() ); |
|
107 | - } |
|
101 | + /** |
|
102 | + * @api |
|
103 | + * @return string the relative path to the theme (ex: `/wp-content/themes/my-timber-theme`) |
|
104 | + */ |
|
105 | + public function path() { |
|
106 | + return TimberURLHelper::get_rel_url( $this->link() ); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @param string $name |
|
111 | - * @param bool $default |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public function theme_mod($name, $default = false) { |
|
115 | - return get_theme_mod($name, $default); |
|
116 | - } |
|
109 | + /** |
|
110 | + * @param string $name |
|
111 | + * @param bool $default |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public function theme_mod($name, $default = false) { |
|
115 | + return get_theme_mod($name, $default); |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * @return array |
|
120 | - */ |
|
121 | - public function theme_mods() { |
|
122 | - return get_theme_mods(); |
|
123 | - } |
|
118 | + /** |
|
119 | + * @return array |
|
120 | + */ |
|
121 | + public function theme_mods() { |
|
122 | + return get_theme_mods(); |
|
123 | + } |
|
124 | 124 | |
125 | 125 | } |
@@ -145,10 +145,10 @@ |
||
145 | 145 | * @return WP_Query |
146 | 146 | */ |
147 | 147 | static function handle_maybe_custom_posts_page( $query ) { |
148 | - if ($custom_posts_page = get_option('page_for_posts')) { |
|
149 | - if ( isset($query->query['p']) && $query->query['p'] == $custom_posts_page ) { |
|
150 | - return new WP_Query(array('post_type' => 'post')); |
|
151 | - } |
|
148 | + if ($custom_posts_page = get_option('page_for_posts')) { |
|
149 | + if ( isset($query->query['p']) && $query->query['p'] == $custom_posts_page ) { |
|
150 | + return new WP_Query(array('post_type' => 'post')); |
|
151 | + } |
|
152 | 152 | } |
153 | 153 | return $query; |
154 | 154 | } |