@@ -24,15 +24,15 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @param array|object $data |
26 | 26 | */ |
27 | - public function __construct( $data ) { |
|
27 | + public function __construct($data) { |
|
28 | 28 | $data = (object) $data; |
29 | - $this->import( $data ); |
|
30 | - $this->import_classes( $data ); |
|
31 | - if ( isset( $this->name ) ) { |
|
29 | + $this->import($data); |
|
30 | + $this->import_classes($data); |
|
31 | + if ( isset($this->name) ) { |
|
32 | 32 | $this->_name = $this->name; |
33 | 33 | } |
34 | 34 | $this->name = $this->name(); |
35 | - $this->add_class( 'menu-item-' . $this->ID ); |
|
35 | + $this->add_class('menu-item-' . $this->ID); |
|
36 | 36 | $this->menu_object = $data; |
37 | 37 | } |
38 | 38 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * add a class the menu item should have |
48 | 48 | * @param string $class_name to be added |
49 | 49 | */ |
50 | - public function add_class( $class_name ) { |
|
50 | + public function add_class($class_name) { |
|
51 | 51 | $this->classes[] = $class_name; |
52 | 52 | $this->class .= ' ' . $class_name; |
53 | 53 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | if ( $title = $this->title() ) { |
62 | 62 | return $title; |
63 | 63 | } |
64 | - if ( isset( $this->_name ) ) { |
|
64 | + if ( isset($this->_name) ) { |
|
65 | 65 | return $this->_name; |
66 | 66 | } |
67 | 67 | return ''; |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | * @return string the slug of the menu item kinda-like-this |
83 | 83 | */ |
84 | 84 | public function slug() { |
85 | - if ( !isset( $this->master_object ) ) { |
|
85 | + if ( !isset($this->master_object) ) { |
|
86 | 86 | $this->master_object = $this->get_master_object(); |
87 | 87 | } |
88 | - if ( isset( $this->master_object->post_name ) && $this->master_object->post_name ) { |
|
88 | + if ( isset($this->master_object->post_name) && $this->master_object->post_name ) { |
|
89 | 89 | return $this->master_object->post_name; |
90 | 90 | } |
91 | 91 | return $this->post_name; |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | * @return mixed whatever object (Post, Term, etc.) the menu item represents |
97 | 97 | */ |
98 | 98 | protected function get_master_object() { |
99 | - if ( isset( $this->_menu_item_object_id ) ) { |
|
100 | - return new $this->PostClass( $this->_menu_item_object_id ); |
|
99 | + if ( isset($this->_menu_item_object_id) ) { |
|
100 | + return new $this->PostClass($this->_menu_item_object_id); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | * @return string an absolute URL http://example.org/my-page |
108 | 108 | */ |
109 | 109 | function get_link() { |
110 | - if ( !isset( $this->url ) || !$this->url ) { |
|
111 | - if ( isset( $this->_menu_item_type ) && $this->_menu_item_type == 'custom' ) { |
|
110 | + if ( !isset($this->url) || !$this->url ) { |
|
111 | + if ( isset($this->_menu_item_type) && $this->_menu_item_type == 'custom' ) { |
|
112 | 112 | $this->url = $this->_menu_item_url; |
113 | - } else if ( isset( $this->menu_object ) && method_exists( $this->menu_object, 'get_link' ) ) { |
|
113 | + } else if ( isset($this->menu_object) && method_exists($this->menu_object, 'get_link') ) { |
|
114 | 114 | $this->url = $this->menu_object->get_link(); |
115 | 115 | } |
116 | 116 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * @return string a relative url /my-page |
124 | 124 | */ |
125 | 125 | function get_path() { |
126 | - return TimberURLHelper::get_rel_url( $this->get_link() ); |
|
126 | + return TimberURLHelper::get_rel_url($this->get_link()); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -131,17 +131,17 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @param TimberMenuItem $item |
133 | 133 | */ |
134 | - function add_child( $item ) { |
|
134 | + function add_child($item) { |
|
135 | 135 | if ( !$this->has_child_class ) { |
136 | - $this->add_class( 'menu-item-has-children' ); |
|
136 | + $this->add_class('menu-item-has-children'); |
|
137 | 137 | $this->has_child_class = true; |
138 | 138 | } |
139 | - if ( !isset( $this->children ) ) { |
|
139 | + if ( !isset($this->children) ) { |
|
140 | 140 | $this->children = array(); |
141 | 141 | } |
142 | 142 | $this->children[] = $item; |
143 | 143 | $item->level = $this->level + 1; |
144 | - if ($item->children) { |
|
144 | + if ( $item->children ) { |
|
145 | 145 | $this->update_child_levels(); |
146 | 146 | } |
147 | 147 | } |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | * @return bool |
153 | 153 | */ |
154 | 154 | function update_child_levels() { |
155 | - if (is_array($this->children)) { |
|
156 | - foreach( $this->children as $child ) { |
|
155 | + if ( is_array($this->children) ) { |
|
156 | + foreach ($this->children as $child) { |
|
157 | 157 | $child->level = $this->level + 1; |
158 | 158 | $child->update_child_levels(); |
159 | 159 | } |
@@ -166,14 +166,14 @@ discard block |
||
166 | 166 | * @internal |
167 | 167 | * @param array|object $data |
168 | 168 | */ |
169 | - function import_classes( $data ) { |
|
169 | + function import_classes($data) { |
|
170 | 170 | if ( is_array($data) ) { |
171 | 171 | $data = (object) $data; |
172 | 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 ) ); |
|
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 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @return array|bool |
183 | 183 | */ |
184 | 184 | function get_children() { |
185 | - if ( isset( $this->children ) ) { |
|
185 | + if ( isset($this->children) ) { |
|
186 | 186 | return $this->children; |
187 | 187 | } |
188 | 188 | return false; |
@@ -201,18 +201,18 @@ discard block |
||
201 | 201 | if ( $this->type != 'custom' ) { |
202 | 202 | return false; |
203 | 203 | } |
204 | - return TimberURLHelper::is_external( $this->url ); |
|
204 | + return TimberURLHelper::is_external($this->url); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
208 | 208 | * @param string $key lookup key |
209 | 209 | * @return mixed whatever value is storied in the database |
210 | 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 ); |
|
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 | 214 | } |
215 | - if ( isset( $this->$key ) ) { |
|
215 | + if ( isset($this->$key) ) { |
|
216 | 216 | return $this->$key; |
217 | 217 | } |
218 | 218 | } |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @return string the public label like Foo |
300 | 300 | */ |
301 | 301 | public function title() { |
302 | - if ( isset( $this->__title ) ) { |
|
302 | + if ( isset($this->__title) ) { |
|
303 | 303 | return $this->__title; |
304 | 304 | } |
305 | 305 | } |
@@ -77,16 +77,16 @@ discard block |
||
77 | 77 | */ |
78 | 78 | function __construct($slug = 0) { |
79 | 79 | $locations = get_nav_menu_locations(); |
80 | - if ($slug != 0 && is_numeric($slug)) { |
|
80 | + if ( $slug != 0 && is_numeric($slug) ) { |
|
81 | 81 | $menu_id = $slug; |
82 | - } else if (is_array($locations) && count($locations)) { |
|
82 | + } else if ( is_array($locations) && count($locations) ) { |
|
83 | 83 | $menu_id = $this->get_menu_id_from_locations($slug, $locations); |
84 | - } else if ($slug === false) { |
|
84 | + } else if ( $slug === false ) { |
|
85 | 85 | $menu_id = false; |
86 | 86 | } else { |
87 | 87 | $menu_id = $this->get_menu_id_from_terms($slug); |
88 | 88 | } |
89 | - if ($menu_id) { |
|
89 | + if ( $menu_id ) { |
|
90 | 90 | $this->init($menu_id); |
91 | 91 | } else { |
92 | 92 | $this->init_as_page_menu(); |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | */ |
100 | 100 | protected function init($menu_id) { |
101 | 101 | $menu = wp_get_nav_menu_items($menu_id); |
102 | - if ($menu) { |
|
102 | + if ( $menu ) { |
|
103 | 103 | _wp_menu_item_classes_by_context($menu); |
104 | - if (is_array($menu)){ |
|
104 | + if ( is_array($menu) ) { |
|
105 | 105 | $menu = self::order_children($menu); |
106 | 106 | } |
107 | 107 | $this->items = $menu; |
@@ -118,12 +118,12 @@ discard block |
||
118 | 118 | */ |
119 | 119 | protected function init_as_page_menu() { |
120 | 120 | $menu = get_pages(); |
121 | - if ($menu) { |
|
122 | - foreach($menu as $mi) { |
|
121 | + if ( $menu ) { |
|
122 | + foreach ($menu as $mi) { |
|
123 | 123 | $mi->__title = $mi->post_title; |
124 | 124 | } |
125 | 125 | _wp_menu_item_classes_by_context($menu); |
126 | - if (is_array($menu)){ |
|
126 | + if ( is_array($menu) ) { |
|
127 | 127 | $menu = self::order_children($menu); |
128 | 128 | } |
129 | 129 | $this->items = $menu; |
@@ -137,13 +137,13 @@ discard block |
||
137 | 137 | * @return integer |
138 | 138 | */ |
139 | 139 | protected function get_menu_id_from_locations($slug, $locations) { |
140 | - if ($slug === 0) { |
|
140 | + if ( $slug === 0 ) { |
|
141 | 141 | $slug = $this->get_menu_id_from_terms($slug); |
142 | 142 | } |
143 | - if (is_numeric($slug)) { |
|
143 | + if ( is_numeric($slug) ) { |
|
144 | 144 | $slug = array_search($slug, $locations); |
145 | 145 | } |
146 | - if (isset($locations[$slug])) { |
|
146 | + if ( isset($locations[$slug]) ) { |
|
147 | 147 | return $locations[$slug]; |
148 | 148 | } |
149 | 149 | } |
@@ -154,20 +154,20 @@ discard block |
||
154 | 154 | * @return int |
155 | 155 | */ |
156 | 156 | protected function get_menu_id_from_terms($slug = 0) { |
157 | - if (!is_numeric($slug) && is_string($slug)) { |
|
157 | + if ( !is_numeric($slug) && is_string($slug) ) { |
|
158 | 158 | //we have a string so lets search for that |
159 | 159 | $menu_id = get_term_by('slug', $slug, 'nav_menu'); |
160 | - if ($menu_id) { |
|
160 | + if ( $menu_id ) { |
|
161 | 161 | return $menu_id; |
162 | 162 | } |
163 | 163 | $menu_id = get_term_by('name', $slug, 'nav_menu'); |
164 | - if ($menu_id) { |
|
164 | + if ( $menu_id ) { |
|
165 | 165 | return $menu_id; |
166 | 166 | } |
167 | 167 | } |
168 | 168 | $menus = get_terms('nav_menu', array('hide_empty' => true)); |
169 | - if (is_array($menus) && count($menus)) { |
|
170 | - if (isset($menus[0]->term_id)) { |
|
169 | + if ( is_array($menus) && count($menus) ) { |
|
170 | + if ( isset($menus[0]->term_id) ) { |
|
171 | 171 | return $menus[0]->term_id; |
172 | 172 | } |
173 | 173 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | */ |
182 | 182 | function find_parent_item_in_menu($menu_items, $parent_id) { |
183 | 183 | foreach ($menu_items as &$item) { |
184 | - if ($item->ID == $parent_id) { |
|
184 | + if ( $item->ID == $parent_id ) { |
|
185 | 185 | return $item; |
186 | 186 | } |
187 | 187 | } |
@@ -196,25 +196,25 @@ discard block |
||
196 | 196 | $index = array(); |
197 | 197 | $menu = array(); |
198 | 198 | foreach ($items as $item) { |
199 | - if (isset($item->title)) { |
|
199 | + if ( isset($item->title) ) { |
|
200 | 200 | //items from wp can come with a $title property which conflicts with methods |
201 | 201 | $item->__title = $item->title; |
202 | 202 | unset($item->title); |
203 | 203 | } |
204 | - if(isset($item->ID)){ |
|
205 | - if (is_object($item) && get_class($item) == 'WP_Post'){ |
|
204 | + if ( isset($item->ID) ) { |
|
205 | + if ( is_object($item) && get_class($item) == 'WP_Post' ) { |
|
206 | 206 | $old_menu_item = $item; |
207 | 207 | $item = new $this->PostClass($item); |
208 | 208 | } |
209 | 209 | $menu_item = new $this->MenuItemClass($item); |
210 | - if (isset($old_menu_item)){ |
|
210 | + if ( isset($old_menu_item) ) { |
|
211 | 211 | $menu_item->import_classes($old_menu_item); |
212 | 212 | } |
213 | 213 | $index[$item->ID] = $menu_item; |
214 | 214 | } |
215 | 215 | } |
216 | 216 | foreach ($index as $item) { |
217 | - if (isset($item->menu_item_parent) && $item->menu_item_parent && isset($index[$item->menu_item_parent])) { |
|
217 | + if ( isset($item->menu_item_parent) && $item->menu_item_parent && isset($index[$item->menu_item_parent]) ) { |
|
218 | 218 | $index[$item->menu_item_parent]->add_child($item); |
219 | 219 | } else { |
220 | 220 | $menu[] = $item; |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * @return array |
228 | 228 | */ |
229 | 229 | function get_items() { |
230 | - if (is_array($this->items)) { |
|
230 | + if ( is_array($this->items) ) { |
|
231 | 231 | return $this->items; |
232 | 232 | } |
233 | 233 | return array(); |
@@ -8,19 +8,19 @@ discard block |
||
8 | 8 | * @return array|bool|null |
9 | 9 | */ |
10 | 10 | static function get_post($query = false, $PostClass = 'TimberPost') { |
11 | - $posts = self::get_posts( $query, $PostClass ); |
|
12 | - if ( $post = reset($posts ) ) { |
|
11 | + $posts = self::get_posts($query, $PostClass); |
|
12 | + if ( $post = reset($posts) ) { |
|
13 | 13 | return $post; |
14 | 14 | } |
15 | 15 | } |
16 | 16 | |
17 | - static function get_posts( $query = false, $PostClass = 'TimberPost', $return_collection = false ) { |
|
18 | - $posts = self::query_posts( $query, $PostClass ); |
|
19 | - return apply_filters('timber_post_getter_get_posts', $posts->get_posts( $return_collection )); |
|
17 | + static function get_posts($query = false, $PostClass = 'TimberPost', $return_collection = false) { |
|
18 | + $posts = self::query_posts($query, $PostClass); |
|
19 | + return apply_filters('timber_post_getter_get_posts', $posts->get_posts($return_collection)); |
|
20 | 20 | } |
21 | 21 | |
22 | - static function query_post( $query = false, $PostClass = 'TimberPost' ) { |
|
23 | - $posts = self::query_posts( $query, $PostClass ); |
|
22 | + static function query_post($query = false, $PostClass = 'TimberPost') { |
|
23 | + $posts = self::query_posts($query, $PostClass); |
|
24 | 24 | if ( method_exists($posts, 'current') && $post = $posts->current() ) { |
25 | 25 | return $post; |
26 | 26 | } |
@@ -31,32 +31,32 @@ discard block |
||
31 | 31 | * @param string $PostClass |
32 | 32 | * @return array|bool|null |
33 | 33 | */ |
34 | - static function query_posts($query = false, $PostClass = 'TimberPost' ) { |
|
35 | - if (self::is_post_class_or_class_map($query)) { |
|
34 | + static function query_posts($query = false, $PostClass = 'TimberPost') { |
|
35 | + if ( self::is_post_class_or_class_map($query) ) { |
|
36 | 36 | $PostClass = $query; |
37 | 37 | $query = false; |
38 | 38 | } |
39 | 39 | |
40 | - if (is_object($query) && !is_a($query, 'WP_Query') ){ |
|
40 | + if ( is_object($query) && !is_a($query, 'WP_Query') ) { |
|
41 | 41 | // The only object other than a query is a type of post object |
42 | - $query = array( $query ); |
|
42 | + $query = array($query); |
|
43 | 43 | } |
44 | 44 | |
45 | - if ( is_array( $query ) && count( $query ) && isset( $query[0] ) && is_object( $query[0] ) ) { |
|
45 | + if ( is_array($query) && count($query) && isset($query[0]) && is_object($query[0]) ) { |
|
46 | 46 | // We have an array of post objects that already have data |
47 | - return new TimberPostsCollection( $query, $PostClass ); |
|
47 | + return new TimberPostsCollection($query, $PostClass); |
|
48 | 48 | } else { |
49 | 49 | // We have a query (of sorts) to work with |
50 | - $tqi = new TimberQueryIterator( $query, $PostClass ); |
|
50 | + $tqi = new TimberQueryIterator($query, $PostClass); |
|
51 | 51 | return $tqi; |
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | - static function get_pids($query){ |
|
55 | + static function get_pids($query) { |
|
56 | 56 | $posts = self::get_posts($query); |
57 | 57 | $pids = array(); |
58 | - foreach($posts as $post){ |
|
59 | - if (isset($post->ID)){ |
|
58 | + foreach ($posts as $post) { |
|
59 | + if ( isset($post->ID) ) { |
|
60 | 60 | $pids[] = $post->ID; |
61 | 61 | } |
62 | 62 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | } |
65 | 65 | |
66 | 66 | static function loop_to_id() { |
67 | - if (!self::wp_query_has_posts()) { return false; } |
|
67 | + if ( !self::wp_query_has_posts() ) { return false; } |
|
68 | 68 | |
69 | 69 | global $wp_query; |
70 | 70 | $post_num = property_exists($wp_query, 'current_post') |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | : 0 |
73 | 73 | ; |
74 | 74 | |
75 | - if (!isset($wp_query->posts[$post_num])) { return false; } |
|
75 | + if ( !isset($wp_query->posts[$post_num]) ) { return false; } |
|
76 | 76 | |
77 | 77 | return $wp_query->posts[$post_num]->ID; |
78 | 78 | } |
@@ -89,13 +89,13 @@ discard block |
||
89 | 89 | * @param string|array $arg |
90 | 90 | * @return bool |
91 | 91 | */ |
92 | - static function is_post_class_or_class_map($arg){ |
|
93 | - if (is_string($arg) && class_exists($arg)) { |
|
92 | + static function is_post_class_or_class_map($arg) { |
|
93 | + if ( is_string($arg) && class_exists($arg) ) { |
|
94 | 94 | return true; |
95 | 95 | } |
96 | - if (is_array($arg)) { |
|
96 | + if ( is_array($arg) ) { |
|
97 | 97 | foreach ($arg as $item) { |
98 | - if (is_string($item) && class_exists($item)) { |
|
98 | + if ( is_string($item) && class_exists($item) ) { |
|
99 | 99 | return true; |
100 | 100 | } |
101 | 101 | } |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @param mixed $pid |
169 | 169 | */ |
170 | 170 | public function __construct($pid = null) { |
171 | - $pid = $this->determine_id( $pid ); |
|
171 | + $pid = $this->determine_id($pid); |
|
172 | 172 | $this->init($pid); |
173 | 173 | } |
174 | 174 | |
@@ -188,13 +188,13 @@ discard block |
||
188 | 188 | && get_class($wp_query->queried_object) == 'WP_Post' |
189 | 189 | ) { |
190 | 190 | $pid = $wp_query->queried_object_id; |
191 | - } else if ( $pid === null && $wp_query->is_home && isset($wp_query->queried_object_id) && $wp_query->queried_object_id ) { |
|
191 | + } else if ( $pid === null && $wp_query->is_home && isset($wp_query->queried_object_id) && $wp_query->queried_object_id ) { |
|
192 | 192 | //hack for static page as home page |
193 | 193 | $pid = $wp_query->queried_object_id; |
194 | 194 | } else if ( $pid === null ) { |
195 | 195 | $gtid = false; |
196 | 196 | $maybe_post = get_post(); |
197 | - if ( isset($maybe_post->ID) ){ |
|
197 | + if ( isset($maybe_post->ID) ) { |
|
198 | 198 | $gtid = true; |
199 | 199 | } |
200 | 200 | if ( $gtid ) { |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * @param string $field |
261 | 261 | * @param mixed $value |
262 | 262 | */ |
263 | - public function update( $field, $value ) { |
|
263 | + public function update($field, $value) { |
|
264 | 264 | if ( isset($this->ID) ) { |
265 | 265 | update_post_meta($this->ID, $field, $value); |
266 | 266 | $this->$field = $value; |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | * @param mixed $pid |
276 | 276 | * @return WP_Post on success |
277 | 277 | */ |
278 | - protected function prepare_post_info( $pid = 0 ) { |
|
278 | + protected function prepare_post_info($pid = 0) { |
|
279 | 279 | if ( is_string($pid) || is_numeric($pid) || (is_object($pid) && !isset($pid->post_title)) || $pid === 0 ) { |
280 | 280 | $pid = self::check_post_id($pid); |
281 | 281 | $post = get_post($pid); |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | * @internal |
298 | 298 | * @return integer ID number of a post |
299 | 299 | */ |
300 | - protected function check_post_id( $pid ) { |
|
300 | + protected function check_post_id($pid) { |
|
301 | 301 | if ( is_numeric($pid) && $pid === 0 ) { |
302 | 302 | $pid = get_the_ID(); |
303 | 303 | return $pid; |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | global $wpdb; |
324 | 324 | $query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s LIMIT 1", $post_name); |
325 | 325 | $result = $wpdb->get_row($query); |
326 | - if (!$result) { |
|
326 | + if ( !$result ) { |
|
327 | 327 | return null; |
328 | 328 | } |
329 | 329 | return $result->ID; |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | $text = TimberHelper::trim_words($text, $len, false); |
363 | 363 | $trimmed = true; |
364 | 364 | } |
365 | - $text = do_shortcode( $text ); |
|
365 | + $text = do_shortcode($text); |
|
366 | 366 | } |
367 | 367 | if ( !strlen($text) ) { |
368 | 368 | $text = TimberHelper::trim_words($this->get_content(), $len, false); |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | } elseif ( $readmore ) { |
395 | 395 | $text .= ' <a href="' . $this->get_permalink() . '" class="read-more">' . trim($readmore) . '</a>'; |
396 | 396 | } |
397 | - if ( !$strip && $last_p_tag && ( strpos($text, '<p>') || strpos($text, '<p ') ) ) { |
|
397 | + if ( !$strip && $last_p_tag && (strpos($text, '<p>') || strpos($text, '<p ')) ) { |
|
398 | 398 | $text .= '</p>'; |
399 | 399 | } |
400 | 400 | } |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | * @internal |
407 | 407 | * @param bool|int $pid a post ID number |
408 | 408 | */ |
409 | - function import_custom( $pid = false ) { |
|
409 | + function import_custom($pid = false) { |
|
410 | 410 | if ( !$pid ) { |
411 | 411 | $pid = $this->ID; |
412 | 412 | } |
@@ -421,13 +421,13 @@ discard block |
||
421 | 421 | * @param int $pid |
422 | 422 | * @return array |
423 | 423 | */ |
424 | - protected function get_post_custom( $pid ) { |
|
424 | + protected function get_post_custom($pid) { |
|
425 | 425 | apply_filters('timber_post_get_meta_pre', array(), $pid, $this); |
426 | 426 | $customs = get_post_custom($pid); |
427 | 427 | if ( !is_array($customs) || empty($customs) ) { |
428 | 428 | return array(); |
429 | 429 | } |
430 | - foreach ( $customs as $key => $value ) { |
|
430 | + foreach ($customs as $key => $value) { |
|
431 | 431 | if ( is_array($value) && count($value) == 1 && isset($value[0]) ) { |
432 | 432 | $value = $value[0]; |
433 | 433 | } |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | * @param bool $taxonomy |
482 | 482 | * @return TimberPost|boolean |
483 | 483 | */ |
484 | - function get_next( $taxonomy = false ) { |
|
484 | + function get_next($taxonomy = false) { |
|
485 | 485 | if ( !isset($this->_next) || !isset($this->_next[$taxonomy]) ) { |
486 | 486 | global $post; |
487 | 487 | $this->_next = array(); |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | $post = $this; |
513 | 513 | $ret = array(); |
514 | 514 | if ( $multipage ) { |
515 | - for ( $i = 1; $i <= $numpages; $i++ ) { |
|
515 | + for ($i = 1; $i <= $numpages; $i++) { |
|
516 | 516 | $link = self::get_wp_link_page($i); |
517 | 517 | $data = array('name' => $i, 'title' => $i, 'text' => $i, 'link' => $link); |
518 | 518 | if ( $i == $page ) { |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | * @param bool $taxonomy |
565 | 565 | * @return TimberPost|boolean |
566 | 566 | */ |
567 | - function get_prev( $taxonomy = false ) { |
|
567 | + function get_prev($taxonomy = false) { |
|
568 | 568 | if ( isset($this->_prev) && isset($this->_prev[$taxonomy]) ) { |
569 | 569 | return $this->_prev[$taxonomy]; |
570 | 570 | } |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | $post->slug = $post->post_name; |
632 | 632 | $customs = $this->get_post_custom($post->ID); |
633 | 633 | $post->custom = $customs; |
634 | - $post = (object) array_merge((array)$customs, (array)$post); |
|
634 | + $post = (object) array_merge((array) $customs, (array) $post); |
|
635 | 635 | return $post; |
636 | 636 | } |
637 | 637 | |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | * @param string $use |
643 | 643 | * @return string |
644 | 644 | */ |
645 | - function get_display_date( $use = 'post_date' ) { |
|
645 | + function get_display_date($use = 'post_date') { |
|
646 | 646 | return date(get_option('date_format'), strtotime($this->$use)); |
647 | 647 | } |
648 | 648 | |
@@ -652,9 +652,9 @@ discard block |
||
652 | 652 | * @param string $date_format |
653 | 653 | * @return string |
654 | 654 | */ |
655 | - function get_date( $date_format = '' ) { |
|
655 | + function get_date($date_format = '') { |
|
656 | 656 | $df = $date_format ? $date_format : get_option('date_format'); |
657 | - $the_date = (string)mysql2date($df, $this->post_date); |
|
657 | + $the_date = (string) mysql2date($df, $this->post_date); |
|
658 | 658 | return apply_filters('get_the_date', $the_date, $df); |
659 | 659 | } |
660 | 660 | |
@@ -663,7 +663,7 @@ discard block |
||
663 | 663 | * @param string $date_format |
664 | 664 | * @return string |
665 | 665 | */ |
666 | - function get_modified_date( $date_format = '' ) { |
|
666 | + function get_modified_date($date_format = '') { |
|
667 | 667 | $df = $date_format ? $date_format : get_option('date_format'); |
668 | 668 | $the_time = $this->get_modified_time($df); |
669 | 669 | return apply_filters('get_the_modified_date', $the_time, $date_format); |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | * @param string $time_format |
675 | 675 | * @return string |
676 | 676 | */ |
677 | - function get_modified_time( $time_format = '' ) { |
|
677 | + function get_modified_time($time_format = '') { |
|
678 | 678 | $tf = $time_format ? $time_format : get_option('time_format'); |
679 | 679 | $the_time = get_post_modified_time($tf, false, $this->ID, true); |
680 | 680 | return apply_filters('get_the_modified_time', $the_time, $time_format); |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | * @param bool|string $childPostClass |
688 | 688 | * @return array |
689 | 689 | */ |
690 | - function get_children( $post_type = 'any', $childPostClass = false ) { |
|
690 | + function get_children($post_type = 'any', $childPostClass = false) { |
|
691 | 691 | if ( $childPostClass === false ) { |
692 | 692 | $childPostClass = $this->PostClass; |
693 | 693 | } |
@@ -695,7 +695,7 @@ discard block |
||
695 | 695 | $post_type = $this->post_type; |
696 | 696 | } |
697 | 697 | $children = get_children('post_parent=' . $this->ID . '&post_type=' . $post_type . '&numberposts=-1&orderby=menu_order title&order=ASC'); |
698 | - foreach ( $children as &$child ) { |
|
698 | + foreach ($children as &$child) { |
|
699 | 699 | $child = new $childPostClass($child->ID); |
700 | 700 | } |
701 | 701 | $children = array_values($children); |
@@ -731,16 +731,16 @@ discard block |
||
731 | 731 | $timber_comments = array(); |
732 | 732 | |
733 | 733 | if ( '' == get_query_var('cpage') && get_option('page_comments') ) { |
734 | - set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 ); |
|
734 | + set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1); |
|
735 | 735 | $overridden_cpage = true; |
736 | 736 | } |
737 | 737 | |
738 | - foreach( $comments as $key => &$comment ) { |
|
738 | + foreach ($comments as $key => &$comment) { |
|
739 | 739 | $timber_comment = new $CommentClass($comment); |
740 | 740 | $timber_comments[$timber_comment->id] = $timber_comment; |
741 | 741 | } |
742 | 742 | |
743 | - foreach( $timber_comments as $key => $comment ) { |
|
743 | + foreach ($timber_comments as $key => $comment) { |
|
744 | 744 | if ( $comment->is_child() ) { |
745 | 745 | unset($timber_comments[$comment->id]); |
746 | 746 | |
@@ -784,7 +784,7 @@ discard block |
||
784 | 784 | * @param string $TermClass |
785 | 785 | * @return array |
786 | 786 | */ |
787 | - function get_terms( $tax = '', $merge = true, $TermClass = '' ) { |
|
787 | + function get_terms($tax = '', $merge = true, $TermClass = '') { |
|
788 | 788 | |
789 | 789 | $TermClass = $TermClass ?: $this->TermClass; |
790 | 790 | |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | $taxonomies = $tax; |
796 | 796 | } |
797 | 797 | if ( is_string($tax) ) { |
798 | - if ( in_array($tax, array('all','any','')) ) { |
|
798 | + if ( in_array($tax, array('all', 'any', '')) ) { |
|
799 | 799 | $taxonomies = get_object_taxonomies($this->post_type); |
800 | 800 | } else { |
801 | 801 | $taxonomies = array($tax); |
@@ -804,8 +804,8 @@ discard block |
||
804 | 804 | |
805 | 805 | $term_class_objects = array(); |
806 | 806 | |
807 | - foreach ( $taxonomies as $taxonomy ) { |
|
808 | - if ( in_array($taxonomy, array('tag','tags')) ) { |
|
807 | + foreach ($taxonomies as $taxonomy) { |
|
808 | + if ( in_array($taxonomy, array('tag', 'tags')) ) { |
|
809 | 809 | $taxonomy = 'post_tag'; |
810 | 810 | } |
811 | 811 | if ( $taxonomy == 'categories' ) { |
@@ -843,11 +843,11 @@ discard block |
||
843 | 843 | * @param string $taxonomy |
844 | 844 | * @return bool |
845 | 845 | */ |
846 | - function has_term( $term_name_or_id, $taxonomy = 'all' ) { |
|
846 | + function has_term($term_name_or_id, $taxonomy = 'all') { |
|
847 | 847 | if ( $taxonomy == 'all' || $taxonomy == 'any' ) { |
848 | 848 | $taxes = get_object_taxonomies($this->post_type, 'names'); |
849 | 849 | $ret = false; |
850 | - foreach ( $taxes as $tax ) { |
|
850 | + foreach ($taxes as $tax) { |
|
851 | 851 | if ( has_term($term_name_or_id, $tax, $this->ID) ) { |
852 | 852 | $ret = true; |
853 | 853 | break; |
@@ -862,7 +862,7 @@ discard block |
||
862 | 862 | * @param string $field |
863 | 863 | * @return TimberImage |
864 | 864 | */ |
865 | - function get_image( $field ) { |
|
865 | + function get_image($field) { |
|
866 | 866 | return new $this->ImageClass($this->$field); |
867 | 867 | } |
868 | 868 | |
@@ -912,7 +912,7 @@ discard block |
||
912 | 912 | * @param int $page |
913 | 913 | * @return string |
914 | 914 | */ |
915 | - function get_content( $len = 0, $page = 0 ) { |
|
915 | + function get_content($len = 0, $page = 0) { |
|
916 | 916 | if ( $len == 0 && $page == 0 && $this->_content ) { |
917 | 917 | return $this->_content; |
918 | 918 | } |
@@ -973,7 +973,7 @@ discard block |
||
973 | 973 | * @param string $field_name |
974 | 974 | * @return mixed |
975 | 975 | */ |
976 | - public function get_field( $field_name ) { |
|
976 | + public function get_field($field_name) { |
|
977 | 977 | $value = apply_filters('timber_post_get_meta_field_pre', null, $this->ID, $field_name, $this); |
978 | 978 | if ( $value === null ) { |
979 | 979 | $value = get_post_meta($this->ID, $field_name); |
@@ -991,7 +991,7 @@ discard block |
||
991 | 991 | /** |
992 | 992 | * @param string $field_name |
993 | 993 | */ |
994 | - function import_field( $field_name ) { |
|
994 | + function import_field($field_name) { |
|
995 | 995 | $this->$field_name = $this->get_field($field_name); |
996 | 996 | } |
997 | 997 | |
@@ -1022,13 +1022,13 @@ discard block |
||
1022 | 1022 | * ``` |
1023 | 1023 | * @return string a space-seperated list of classes |
1024 | 1024 | */ |
1025 | - public function post_class( $class='' ) { |
|
1025 | + public function post_class($class = '') { |
|
1026 | 1026 | global $post; |
1027 | 1027 | $old_global_post = $post; |
1028 | 1028 | $post = $this; |
1029 | 1029 | $class_array = get_post_class($class, $this->ID); |
1030 | 1030 | $post = $old_global_post; |
1031 | - if ( is_array($class_array) ){ |
|
1031 | + if ( is_array($class_array) ) { |
|
1032 | 1032 | return implode(' ', $class_array); |
1033 | 1033 | } |
1034 | 1034 | return $class_array; |
@@ -1130,8 +1130,8 @@ discard block |
||
1130 | 1130 | * @param string|bool $childPostClass _optional_ a custom post class (ex: 'MyTimberPost') to return the objects as. By default (false) it will use TimberPost::$post_class value. |
1131 | 1131 | * @return array |
1132 | 1132 | */ |
1133 | - public function children( $post_type = 'any', $childPostClass = false ) { |
|
1134 | - return $this->get_children( $post_type, $childPostClass ); |
|
1133 | + public function children($post_type = 'any', $childPostClass = false) { |
|
1134 | + return $this->get_children($post_type, $childPostClass); |
|
1135 | 1135 | } |
1136 | 1136 | |
1137 | 1137 | /** |
@@ -1155,7 +1155,7 @@ discard block |
||
1155 | 1155 | * ``` |
1156 | 1156 | * @return bool|array |
1157 | 1157 | */ |
1158 | - public function comments( $count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment' ) { |
|
1158 | + public function comments($count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment') { |
|
1159 | 1159 | return $this->get_comments($count, $order, $type, $status, $CommentClass); |
1160 | 1160 | } |
1161 | 1161 | |
@@ -1172,7 +1172,7 @@ discard block |
||
1172 | 1172 | * @param int $page |
1173 | 1173 | * @return string |
1174 | 1174 | */ |
1175 | - public function content( $page = 0 ) { |
|
1175 | + public function content($page = 0) { |
|
1176 | 1176 | return $this->get_content(0, $page); |
1177 | 1177 | } |
1178 | 1178 | |
@@ -1201,7 +1201,7 @@ discard block |
||
1201 | 1201 | * @param string $date_format |
1202 | 1202 | * @return string |
1203 | 1203 | */ |
1204 | - public function date( $date_format = '' ) { |
|
1204 | + public function date($date_format = '') { |
|
1205 | 1205 | return $this->get_date($date_format); |
1206 | 1206 | } |
1207 | 1207 | |
@@ -1237,7 +1237,7 @@ discard block |
||
1237 | 1237 | * @param string $field_name |
1238 | 1238 | * @return mixed |
1239 | 1239 | */ |
1240 | - public function meta( $field_name = null ) { |
|
1240 | + public function meta($field_name = null) { |
|
1241 | 1241 | if ( $field_name === null ) { |
1242 | 1242 | //on the off-chance the field is actually named meta |
1243 | 1243 | $field_name = 'meta'; |
@@ -1248,7 +1248,7 @@ discard block |
||
1248 | 1248 | /** |
1249 | 1249 | * @return string |
1250 | 1250 | */ |
1251 | - public function name(){ |
|
1251 | + public function name() { |
|
1252 | 1252 | return $this->title(); |
1253 | 1253 | } |
1254 | 1254 | |
@@ -1256,7 +1256,7 @@ discard block |
||
1256 | 1256 | * @param string $date_format |
1257 | 1257 | * @return string |
1258 | 1258 | */ |
1259 | - public function modified_date( $date_format = '' ) { |
|
1259 | + public function modified_date($date_format = '') { |
|
1260 | 1260 | return $this->get_modified_date($date_format); |
1261 | 1261 | } |
1262 | 1262 | |
@@ -1264,7 +1264,7 @@ discard block |
||
1264 | 1264 | * @param string $time_format |
1265 | 1265 | * @return string |
1266 | 1266 | */ |
1267 | - public function modified_time( $time_format = '' ) { |
|
1267 | + public function modified_time($time_format = '') { |
|
1268 | 1268 | return $this->get_modified_time($time_format); |
1269 | 1269 | } |
1270 | 1270 | |
@@ -1273,7 +1273,7 @@ discard block |
||
1273 | 1273 | * @param bool $in_same_cat |
1274 | 1274 | * @return mixed |
1275 | 1275 | */ |
1276 | - public function next( $in_same_cat = false ) { |
|
1276 | + public function next($in_same_cat = false) { |
|
1277 | 1277 | return $this->get_next($in_same_cat); |
1278 | 1278 | } |
1279 | 1279 | |
@@ -1331,7 +1331,7 @@ discard block |
||
1331 | 1331 | * @param bool $in_same_cat |
1332 | 1332 | * @return mixed |
1333 | 1333 | */ |
1334 | - public function prev( $in_same_cat = false ) { |
|
1334 | + public function prev($in_same_cat = false) { |
|
1335 | 1335 | return $this->get_prev($in_same_cat); |
1336 | 1336 | } |
1337 | 1337 | |
@@ -1343,7 +1343,7 @@ discard block |
||
1343 | 1343 | * @param bool $merge Should the resulting array be one big one (true)? Or should it be an array of sub-arrays for each taxonomy (false)? |
1344 | 1344 | * @return array |
1345 | 1345 | */ |
1346 | - public function terms( $tax = '', $merge = true ) { |
|
1346 | + public function terms($tax = '', $merge = true) { |
|
1347 | 1347 | return $this->get_terms($tax, $merge); |
1348 | 1348 | } |
1349 | 1349 |
@@ -1,50 +1,50 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Exit if accessed directly |
4 | -if ( !defined( 'ABSPATH' ) ) |
|
4 | +if ( !defined('ABSPATH') ) |
|
5 | 5 | exit; |
6 | 6 | |
7 | 7 | class TimberPostsCollection extends ArrayObject { |
8 | 8 | |
9 | - public function __construct( $posts = array(), $post_class = 'TimberPost' ) { |
|
9 | + public function __construct($posts = array(), $post_class = 'TimberPost') { |
|
10 | 10 | $returned_posts = array(); |
11 | - if ( is_null( $posts ) ){ |
|
11 | + if ( is_null($posts) ) { |
|
12 | 12 | $posts = array(); |
13 | 13 | } |
14 | - foreach ( $posts as $post_object ) { |
|
14 | + foreach ($posts as $post_object) { |
|
15 | 15 | $post_class_use = $post_class; |
16 | 16 | |
17 | - if ( is_array( $post_class ) ) { |
|
18 | - $post_type = get_post_type( $post_object ); |
|
17 | + if ( is_array($post_class) ) { |
|
18 | + $post_type = get_post_type($post_object); |
|
19 | 19 | $post_class_use = 'TimberPost'; |
20 | 20 | |
21 | - if ( isset( $post_class[$post_type] ) ) { |
|
21 | + if ( isset($post_class[$post_type]) ) { |
|
22 | 22 | $post_class_use = $post_class[$post_type]; |
23 | 23 | |
24 | 24 | } else { |
25 | - if ( is_array( $post_class ) ) { |
|
26 | - TimberHelper::error_log( $post_type . ' of ' . $post_object->ID . ' not found in ' . print_r( $post_class, true ) ); |
|
25 | + if ( is_array($post_class) ) { |
|
26 | + TimberHelper::error_log($post_type . ' of ' . $post_object->ID . ' not found in ' . print_r($post_class, true)); |
|
27 | 27 | } else { |
28 | - TimberHelper::error_log( $post_type . ' not found in ' . $post_class ); |
|
28 | + TimberHelper::error_log($post_type . ' not found in ' . $post_class); |
|
29 | 29 | } |
30 | 30 | } |
31 | 31 | } |
32 | 32 | |
33 | 33 | // Don't create yet another object if $post_object is already of the right type |
34 | - if ( is_a( $post_object, $post_class_use ) ) { |
|
34 | + if ( is_a($post_object, $post_class_use) ) { |
|
35 | 35 | $post = $post_object; |
36 | 36 | } else { |
37 | - $post = new $post_class_use( $post_object ); |
|
37 | + $post = new $post_class_use($post_object); |
|
38 | 38 | } |
39 | 39 | |
40 | - if ( isset( $post->ID ) ) { |
|
40 | + if ( isset($post->ID) ) { |
|
41 | 41 | $returned_posts[] = $post; |
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | 45 | $returned_posts = self::maybe_set_preview($returned_posts); |
46 | 46 | |
47 | - parent::__construct( $returned_posts, $flags = 0, 'TimberPostsIterator' ); |
|
47 | + parent::__construct($returned_posts, $flags = 0, 'TimberPostsIterator'); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | public function get_posts() { |
@@ -55,17 +55,17 @@ discard block |
||
55 | 55 | * @param array $posts |
56 | 56 | * @return array |
57 | 57 | */ |
58 | - static function maybe_set_preview( $posts ) { |
|
59 | - if ( is_array( $posts ) && isset( $_GET['preview'] ) && $_GET['preview'] |
|
60 | - && isset( $_GET['preview_id'] ) && $_GET['preview_id'] |
|
61 | - && current_user_can( 'edit_post', $_GET['preview_id'] ) ) { |
|
58 | + static function maybe_set_preview($posts) { |
|
59 | + if ( is_array($posts) && isset($_GET['preview']) && $_GET['preview'] |
|
60 | + && isset($_GET['preview_id']) && $_GET['preview_id'] |
|
61 | + && current_user_can('edit_post', $_GET['preview_id']) ) { |
|
62 | 62 | // No need to check the nonce, that already happened in _show_post_preview on init |
63 | 63 | |
64 | 64 | $preview_id = $_GET['preview_id']; |
65 | - foreach( $posts as &$post ) { |
|
66 | - if ( is_object( $post ) && $post->ID == $preview_id ) { |
|
65 | + foreach ($posts as &$post) { |
|
66 | + if ( is_object($post) && $post->ID == $preview_id ) { |
|
67 | 67 | // Based on _set_preview( $post ), but adds import_custom |
68 | - $preview = wp_get_post_autosave( $preview_id ); |
|
68 | + $preview = wp_get_post_autosave($preview_id); |
|
69 | 69 | if ( is_object($preview) ) { |
70 | 70 | |
71 | 71 | $preview = sanitize_post($preview); |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | $post->post_content = $preview->post_content; |
74 | 74 | $post->post_title = $preview->post_title; |
75 | 75 | $post->post_excerpt = $preview->post_excerpt; |
76 | - $post->import_custom( $preview_id ); |
|
76 | + $post->import_custom($preview_id); |
|
77 | 77 | |
78 | - add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 ); |
|
78 | + add_filter('get_the_terms', '_wp_preview_terms_filter', 10, 3); |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( !defined( 'ABSPATH' ) ) |
|
3 | +if ( !defined('ABSPATH') ) |
|
4 | 4 | exit; |
5 | 5 | |
6 | 6 | class TimberQueryIterator implements Iterator { |
@@ -13,38 +13,38 @@ discard block |
||
13 | 13 | private $_query = null; |
14 | 14 | private $_posts_class = 'TimberPost'; |
15 | 15 | |
16 | - public function __construct( $query = false, $posts_class = 'TimberPost' ) { |
|
17 | - add_action( 'pre_get_posts', array($this, 'fix_number_posts_wp_quirk' )); |
|
16 | + public function __construct($query = false, $posts_class = 'TimberPost') { |
|
17 | + add_action('pre_get_posts', array($this, 'fix_number_posts_wp_quirk')); |
|
18 | 18 | if ( $posts_class ) |
19 | 19 | $this->_posts_class = $posts_class; |
20 | 20 | |
21 | - if ( is_a( $query, 'WP_Query' ) ) { |
|
21 | + if ( is_a($query, 'WP_Query') ) { |
|
22 | 22 | // We got a full-fledged WP Query, look no further! |
23 | 23 | $the_query = $query; |
24 | 24 | |
25 | 25 | } elseif ( false === $query ) { |
26 | 26 | // If query is explicitly set to false, use the main loop |
27 | 27 | global $wp_query; |
28 | - $the_query =& $wp_query; |
|
28 | + $the_query = & $wp_query; |
|
29 | 29 | //if we're on a custom posts page? |
30 | 30 | $the_query = self::handle_maybe_custom_posts_page($the_query); |
31 | - } elseif ( TimberHelper::is_array_assoc( $query ) || ( is_string( $query ) && strstr( $query, '=' ) ) ) { |
|
31 | + } elseif ( TimberHelper::is_array_assoc($query) || (is_string($query) && strstr($query, '=')) ) { |
|
32 | 32 | // We have a regularly formed WP query string or array to use |
33 | - $the_query = new WP_Query( $query ); |
|
33 | + $the_query = new WP_Query($query); |
|
34 | 34 | |
35 | - } elseif ( is_numeric( $query ) || is_string( $query ) ) { |
|
35 | + } elseif ( is_numeric($query) || is_string($query) ) { |
|
36 | 36 | // We have what could be a post name or post ID to pull out |
37 | - $the_query = self::get_query_from_string( $query ); |
|
37 | + $the_query = self::get_query_from_string($query); |
|
38 | 38 | |
39 | - } elseif ( is_array( $query ) && count( $query ) && ( is_integer( $query[0] ) || is_string( $query[0] ) ) ) { |
|
39 | + } elseif ( is_array($query) && count($query) && (is_integer($query[0]) || is_string($query[0])) ) { |
|
40 | 40 | // We have a list of pids (post IDs) to extract from |
41 | - $the_query = self::get_query_from_array_of_ids( $query ); |
|
42 | - } elseif ( is_array($query) && empty($query)) { |
|
41 | + $the_query = self::get_query_from_array_of_ids($query); |
|
42 | + } elseif ( is_array($query) && empty($query) ) { |
|
43 | 43 | // it's an empty array |
44 | 44 | $the_query = array(); |
45 | 45 | } else { |
46 | - TimberHelper::error_log( 'I have failed you! in ' . basename( __FILE__ ) . '::' . __LINE__ ); |
|
47 | - TimberHelper::error_log( $query ); |
|
46 | + TimberHelper::error_log('I have failed you! in ' . basename(__FILE__) . '::' . __LINE__); |
|
47 | + TimberHelper::error_log($query); |
|
48 | 48 | |
49 | 49 | // We have failed hard, at least let get something. |
50 | 50 | $the_query = new WP_Query(); |
@@ -54,49 +54,49 @@ discard block |
||
54 | 54 | |
55 | 55 | } |
56 | 56 | |
57 | - public function get_posts( $return_collection = false ) { |
|
58 | - if (isset($this->_query->posts)){ |
|
59 | - $posts = new TimberPostsCollection( $this->_query->posts, $this->_posts_class ); |
|
60 | - return ( $return_collection ) ? $posts : $posts->get_posts(); |
|
57 | + public function get_posts($return_collection = false) { |
|
58 | + if ( isset($this->_query->posts) ) { |
|
59 | + $posts = new TimberPostsCollection($this->_query->posts, $this->_posts_class); |
|
60 | + return ($return_collection) ? $posts : $posts->get_posts(); |
|
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | 64 | // |
65 | 65 | // GET POSTS |
66 | 66 | // |
67 | - public static function get_query_from_array_of_ids( $query = array() ) { |
|
68 | - if ( !is_array( $query ) || !count( $query ) ) |
|
67 | + public static function get_query_from_array_of_ids($query = array()) { |
|
68 | + if ( !is_array($query) || !count($query) ) |
|
69 | 69 | return null; |
70 | 70 | |
71 | - return new WP_Query( array( |
|
71 | + return new WP_Query(array( |
|
72 | 72 | 'post_type'=> 'any', |
73 | 73 | 'ignore_sticky_posts' => true, |
74 | 74 | 'post__in' => $query, |
75 | 75 | 'orderby' => 'post__in', |
76 | 76 | 'nopaging' => true |
77 | - ) ); |
|
77 | + )); |
|
78 | 78 | } |
79 | 79 | |
80 | - public static function get_query_from_string( $string = '' ) { |
|
80 | + public static function get_query_from_string($string = '') { |
|
81 | 81 | $post_type = false; |
82 | 82 | |
83 | - if ( is_string( $string ) && strstr( $string, '#' ) ) { |
|
83 | + if ( is_string($string) && strstr($string, '#') ) { |
|
84 | 84 | //we have a post_type directive here |
85 | - list( $post_type, $string ) = explode( '#', $string ); |
|
85 | + list($post_type, $string) = explode('#', $string); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | $query = array( |
89 | - 'post_type' => ( $post_type ) ? $post_type : 'any' |
|
89 | + 'post_type' => ($post_type) ? $post_type : 'any' |
|
90 | 90 | ); |
91 | 91 | |
92 | - if ( is_numeric( $string ) ) { |
|
92 | + if ( is_numeric($string) ) { |
|
93 | 93 | $query['p'] = $string; |
94 | 94 | |
95 | 95 | } else { |
96 | 96 | $query['name'] = $string; |
97 | 97 | } |
98 | 98 | |
99 | - return new WP_Query( $query ); |
|
99 | + return new WP_Query($query); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | // |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | |
115 | 115 | // Sets up the global post, but also return the post, for use in Twig template |
116 | 116 | $posts_class = $this->_posts_class; |
117 | - return new $posts_class( $post ); |
|
117 | + return new $posts_class($post); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -131,10 +131,10 @@ discard block |
||
131 | 131 | } |
132 | 132 | |
133 | 133 | //get_posts users numberposts |
134 | - static function fix_number_posts_wp_quirk( $query ) { |
|
135 | - if (isset($query->query) && isset($query->query['numberposts']) |
|
136 | - && !isset($query->query['posts_per_page'])) { |
|
137 | - $query->set( 'posts_per_page', $query->query['numberposts'] ); |
|
134 | + static function fix_number_posts_wp_quirk($query) { |
|
135 | + if ( isset($query->query) && isset($query->query['numberposts']) |
|
136 | + && !isset($query->query['posts_per_page']) ) { |
|
137 | + $query->set('posts_per_page', $query->query['numberposts']); |
|
138 | 138 | } |
139 | 139 | return $query; |
140 | 140 | } |
@@ -144,8 +144,8 @@ discard block |
||
144 | 144 | * @param WP_Query $query the original query recived from WordPress |
145 | 145 | * @return WP_Query |
146 | 146 | */ |
147 | - static function handle_maybe_custom_posts_page( $query ) { |
|
148 | - if ($custom_posts_page = get_option('page_for_posts')) { |
|
147 | + static function handle_maybe_custom_posts_page($query) { |
|
148 | + if ( $custom_posts_page = get_option('page_for_posts') ) { |
|
149 | 149 | if ( isset($query->query['p']) && $query->query['p'] == $custom_posts_page ) { |
150 | 150 | return new WP_Query(array('post_type' => 'post')); |
151 | 151 | } |
@@ -5,7 +5,7 @@ |
||
5 | 5 | /** |
6 | 6 | * @deprecated since 0.21.1 use Upstatement/routes instead |
7 | 7 | */ |
8 | - public static function init( $timber ) { |
|
8 | + public static function init($timber) { |
|
9 | 9 | // Install ourselves in Timber |
10 | 10 | $timber->routes = new TimberRoutes(); |
11 | 11 | } |
@@ -101,10 +101,10 @@ discard block |
||
101 | 101 | * ``` |
102 | 102 | * @param string|int $site_name_or_id |
103 | 103 | */ |
104 | - function __construct( $site_name_or_id = null ) { |
|
104 | + function __construct($site_name_or_id = null) { |
|
105 | 105 | $this->init(); |
106 | 106 | if ( is_multisite() ) { |
107 | - $this->init_as_multisite( $site_name_or_id ); |
|
107 | + $this->init_as_multisite($site_name_or_id); |
|
108 | 108 | } else { |
109 | 109 | $this->init_as_singlesite(); |
110 | 110 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * @internal |
115 | 115 | * @param string|int $site_name_or_id |
116 | 116 | */ |
117 | - protected function init_as_multisite( $site_name_or_id ) { |
|
117 | + protected function init_as_multisite($site_name_or_id) { |
|
118 | 118 | if ( $site_name_or_id === null ) { |
119 | 119 | //this is necessary for some reason, otherwise returns 1 all the time |
120 | 120 | if ( is_multisite() ) { |
@@ -122,17 +122,17 @@ discard block |
||
122 | 122 | $site_name_or_id = get_current_blog_id(); |
123 | 123 | } |
124 | 124 | } |
125 | - $info = get_blog_details( $site_name_or_id ); |
|
126 | - $this->import( $info ); |
|
125 | + $info = get_blog_details($site_name_or_id); |
|
126 | + $this->import($info); |
|
127 | 127 | $this->ID = $info->blog_id; |
128 | 128 | $this->id = $this->ID; |
129 | 129 | $this->name = $this->blogname; |
130 | 130 | $this->title = $this->blogname; |
131 | 131 | $this->url = $this->siteurl; |
132 | - $theme_slug = get_blog_option( $info->blog_id, 'stylesheet' ); |
|
133 | - $this->theme = new TimberTheme( $theme_slug ); |
|
134 | - $this->description = get_blog_option( $info->blog_id, 'blogdescription' ); |
|
135 | - $this->admin_email = get_blog_option( $info->blog_id, 'admin_email' ); |
|
132 | + $theme_slug = get_blog_option($info->blog_id, 'stylesheet'); |
|
133 | + $this->theme = new TimberTheme($theme_slug); |
|
134 | + $this->description = get_blog_option($info->blog_id, 'blogdescription'); |
|
135 | + $this->admin_email = get_blog_option($info->blog_id, 'admin_email'); |
|
136 | 136 | $this->multisite = true; |
137 | 137 | } |
138 | 138 | |
@@ -141,13 +141,13 @@ discard block |
||
141 | 141 | * @internal |
142 | 142 | */ |
143 | 143 | protected function init_as_singlesite() { |
144 | - $this->admin_email = get_bloginfo( 'admin_email' ); |
|
145 | - $this->name = get_bloginfo( 'name' ); |
|
144 | + $this->admin_email = get_bloginfo('admin_email'); |
|
145 | + $this->name = get_bloginfo('name'); |
|
146 | 146 | $this->title = $this->name; |
147 | - $this->description = get_bloginfo( 'description' ); |
|
148 | - $this->url = get_bloginfo( 'url' ); |
|
147 | + $this->description = get_bloginfo('description'); |
|
148 | + $this->url = get_bloginfo('url'); |
|
149 | 149 | $this->theme = new TimberTheme(); |
150 | - $this->language_attributes = TimberHelper::function_wrapper( 'language_attributes' ); |
|
150 | + $this->language_attributes = TimberHelper::function_wrapper('language_attributes'); |
|
151 | 151 | $this->multisite = false; |
152 | 152 | } |
153 | 153 | |
@@ -156,16 +156,16 @@ discard block |
||
156 | 156 | * @internal |
157 | 157 | */ |
158 | 158 | protected function init() { |
159 | - $this->rdf = get_bloginfo( 'rdf_url' ); |
|
160 | - $this->rss = get_bloginfo( 'rss_url' ); |
|
161 | - $this->rss2 = get_bloginfo( 'rss2_url' ); |
|
162 | - $this->atom = get_bloginfo( 'atom_url' ); |
|
163 | - $this->language = get_bloginfo( 'language' ); |
|
164 | - $this->charset = get_bloginfo( 'charset' ); |
|
165 | - $this->pingback = get_bloginfo( 'pingback_url' ); |
|
166 | - $this->language_attributes = TimberHelper::function_wrapper( 'language_attributes' ); |
|
159 | + $this->rdf = get_bloginfo('rdf_url'); |
|
160 | + $this->rss = get_bloginfo('rss_url'); |
|
161 | + $this->rss2 = get_bloginfo('rss2_url'); |
|
162 | + $this->atom = get_bloginfo('atom_url'); |
|
163 | + $this->language = get_bloginfo('language'); |
|
164 | + $this->charset = get_bloginfo('charset'); |
|
165 | + $this->pingback = get_bloginfo('pingback_url'); |
|
166 | + $this->language_attributes = TimberHelper::function_wrapper('language_attributes'); |
|
167 | 167 | /* deprecated benath this comment */ |
168 | - $this->pingback_url = get_bloginfo( 'pingback_url' ); |
|
168 | + $this->pingback_url = get_bloginfo('pingback_url'); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | * @param string $field |
175 | 175 | * @return mixed |
176 | 176 | */ |
177 | - function __get( $field ) { |
|
178 | - if ( !isset( $this->$field ) ) { |
|
177 | + function __get($field) { |
|
178 | + if ( !isset($this->$field) ) { |
|
179 | 179 | if ( is_multisite() ) { |
180 | - $this->$field = get_blog_option( $this->ID, $field ); |
|
180 | + $this->$field = get_blog_option($this->ID, $field); |
|
181 | 181 | } else { |
182 | - $this->$field = get_option( $field ); |
|
182 | + $this->$field = get_option($field); |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | return $this->$field; |
@@ -226,8 +226,8 @@ discard block |
||
226 | 226 | /** |
227 | 227 | * @ignore |
228 | 228 | */ |
229 | - public function meta( $field ) { |
|
230 | - return $this->__get( $field ); |
|
229 | + public function meta($field) { |
|
230 | + return $this->__get($field); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -236,12 +236,12 @@ discard block |
||
236 | 236 | * @param string $key |
237 | 237 | * @param mixed $value |
238 | 238 | */ |
239 | - public function update( $key, $value ) { |
|
240 | - $value = apply_filters( 'timber_site_set_meta', $value, $key, $this->ID, $this ); |
|
239 | + public function update($key, $value) { |
|
240 | + $value = apply_filters('timber_site_set_meta', $value, $key, $this->ID, $this); |
|
241 | 241 | if ( is_multisite() ) { |
242 | - update_blog_option( $this->ID, $key, $value ); |
|
242 | + update_blog_option($this->ID, $key, $value); |
|
243 | 243 | } else { |
244 | - update_option( $key, $value ); |
|
244 | + update_option($key, $value); |
|
245 | 245 | } |
246 | 246 | $this->$key = $value; |
247 | 247 | } |
@@ -9,40 +9,40 @@ discard block |
||
9 | 9 | * @param string $TermClass |
10 | 10 | * @return mixed |
11 | 11 | */ |
12 | - public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm'){ |
|
13 | - if (is_string($maybe_args) && !strstr($maybe_args, '=')){ |
|
12 | + public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm') { |
|
13 | + if ( is_string($maybe_args) && !strstr($maybe_args, '=') ) { |
|
14 | 14 | //the user is sending the $TermClass in the second argument |
15 | 15 | $TermClass = $maybe_args; |
16 | 16 | } |
17 | - if (is_string($maybe_args) && strstr($maybe_args, '=')){ |
|
17 | + if ( is_string($maybe_args) && strstr($maybe_args, '=') ) { |
|
18 | 18 | parse_str($maybe_args, $maybe_args); |
19 | 19 | } |
20 | - if (is_string($args) && strstr($args, '=')){ |
|
20 | + if ( is_string($args) && strstr($args, '=') ) { |
|
21 | 21 | //a string and a query string! |
22 | 22 | $parsed = TimberTermGetter::get_term_query_from_query_string($args); |
23 | - if (is_array($maybe_args)){ |
|
23 | + if ( is_array($maybe_args) ) { |
|
24 | 24 | $parsed->args = array_merge($parsed->args, $maybe_args); |
25 | 25 | } |
26 | 26 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
27 | - } else if (is_string($args)){ |
|
27 | + } else if ( is_string($args) ) { |
|
28 | 28 | //its just a string with a single taxonomy |
29 | 29 | $parsed = TimberTermGetter::get_term_query_from_string($args); |
30 | - if (is_array($maybe_args)){ |
|
30 | + if ( is_array($maybe_args) ) { |
|
31 | 31 | $parsed->args = array_merge($parsed->args, $maybe_args); |
32 | 32 | } |
33 | 33 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
34 | - } else if (is_array($args) && TimberHelper::is_array_assoc($args)){ |
|
34 | + } else if ( is_array($args) && TimberHelper::is_array_assoc($args) ) { |
|
35 | 35 | //its an associative array, like a good ole query |
36 | 36 | $parsed = TimberTermGetter::get_term_query_from_assoc_array($args); |
37 | 37 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
38 | - } else if (is_array($args)){ |
|
38 | + } else if ( is_array($args) ) { |
|
39 | 39 | //its just an array of strings or IDs (hopefully) |
40 | 40 | $parsed = TimberTermGetter::get_term_query_from_array($args); |
41 | - if (is_array($maybe_args)){ |
|
41 | + if ( is_array($maybe_args) ) { |
|
42 | 42 | $parsed->args = array_merge($parsed->args, $maybe_args); |
43 | 43 | } |
44 | 44 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
45 | - } else if (is_null($args)) { |
|
45 | + } else if ( is_null($args) ) { |
|
46 | 46 | return self::handle_term_query(get_taxonomies(), array(), $TermClass); |
47 | 47 | } |
48 | 48 | return null; |
@@ -54,18 +54,18 @@ discard block |
||
54 | 54 | * @param string $TermClass |
55 | 55 | * @return mixed |
56 | 56 | */ |
57 | - public static function handle_term_query($taxonomies, $args, $TermClass){ |
|
58 | - if (!isset($args['hide_empty'])){ |
|
57 | + public static function handle_term_query($taxonomies, $args, $TermClass) { |
|
58 | + if ( !isset($args['hide_empty']) ) { |
|
59 | 59 | $args['hide_empty'] = false; |
60 | 60 | } |
61 | - if (isset($args['term_id']) && is_int($args['term_id'])){ |
|
61 | + if ( isset($args['term_id']) && is_int($args['term_id']) ) { |
|
62 | 62 | $args['term_id'] = array($args['term_id']); |
63 | 63 | } |
64 | - if (isset($args['term_id'])){ |
|
64 | + if ( isset($args['term_id']) ) { |
|
65 | 65 | $args['include'] = $args['term_id']; |
66 | 66 | } |
67 | 67 | $terms = get_terms($taxonomies, $args); |
68 | - foreach($terms as &$term){ |
|
68 | + foreach ($terms as &$term) { |
|
69 | 69 | $term = new $TermClass($term->term_id, $term->taxonomy); |
70 | 70 | } |
71 | 71 | return $terms; |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | public static function get_term_query_from_string($taxs) { |
90 | 90 | $ret = new stdClass(); |
91 | 91 | $ret->args = array(); |
92 | - if (is_string($taxs)) { |
|
92 | + if ( is_string($taxs) ) { |
|
93 | 93 | $taxs = array($taxs); |
94 | 94 | } |
95 | 95 | $ret->taxonomies = self::correct_taxonomy_names($taxs); |
@@ -103,17 +103,17 @@ discard block |
||
103 | 103 | public static function get_term_query_from_assoc_array($args) { |
104 | 104 | $ret = new stdClass(); |
105 | 105 | $ret->args = $args; |
106 | - if (isset($ret->args['tax'])) { |
|
106 | + if ( isset($ret->args['tax']) ) { |
|
107 | 107 | $ret->taxonomies = $ret->args['tax']; |
108 | - } else if (isset($ret->args['taxonomies'])) { |
|
108 | + } else if ( isset($ret->args['taxonomies']) ) { |
|
109 | 109 | $ret->taxonomies = $ret->args['taxonomies']; |
110 | - } else if (isset($ret->args['taxs'])) { |
|
110 | + } else if ( isset($ret->args['taxs']) ) { |
|
111 | 111 | $ret->taxonomies = $ret->args['taxs']; |
112 | - } else if (isset($ret->args['taxonomy'])) { |
|
112 | + } else if ( isset($ret->args['taxonomy']) ) { |
|
113 | 113 | $ret->taxonomies = $ret->args['taxonomy']; |
114 | 114 | } |
115 | - if (isset($ret->taxonomies)) { |
|
116 | - if (is_string($ret->taxonomies)) { |
|
115 | + if ( isset($ret->taxonomies) ) { |
|
116 | + if ( is_string($ret->taxonomies) ) { |
|
117 | 117 | $ret->taxonomies = array($ret->taxonomies); |
118 | 118 | } |
119 | 119 | $ret->taxonomies = self::correct_taxonomy_names($ret->taxonomies); |
@@ -128,11 +128,11 @@ discard block |
||
128 | 128 | * @return stdClass |
129 | 129 | */ |
130 | 130 | public static function get_term_query_from_array($args) { |
131 | - if (is_array($args) && !empty($args)) { |
|
131 | + if ( is_array($args) && !empty($args) ) { |
|
132 | 132 | //okay its an array with content |
133 | - if (is_int($args[0])) { |
|
133 | + if ( is_int($args[0]) ) { |
|
134 | 134 | return self::get_term_query_from_array_of_ids($args); |
135 | - } else if (is_string($args[0])) { |
|
135 | + } else if ( is_string($args[0]) ) { |
|
136 | 136 | return self::get_term_query_from_array_of_strings($args); |
137 | 137 | } |
138 | 138 | } |
@@ -166,13 +166,13 @@ discard block |
||
166 | 166 | * @return array |
167 | 167 | */ |
168 | 168 | private static function correct_taxonomy_names($taxs) { |
169 | - if (is_string($taxs)) { |
|
169 | + if ( is_string($taxs) ) { |
|
170 | 170 | $taxs = array($taxs); |
171 | 171 | } |
172 | 172 | foreach ($taxs as &$tax) { |
173 | - if ($tax == 'tags' || $tax == 'tag') { |
|
173 | + if ( $tax == 'tags' || $tax == 'tag' ) { |
|
174 | 174 | $tax = 'post_tag'; |
175 | - } else if ($tax == 'categories') { |
|
175 | + } else if ( $tax == 'categories' ) { |
|
176 | 176 | $tax = 'category'; |
177 | 177 | } |
178 | 178 | } |