@@ -33,19 +33,19 @@ discard block |
||
33 | 33 | |
34 | 34 | public function enable() { |
35 | 35 | |
36 | - add_filter( 'template_include', array( $this, 'template_include' ), 9 ); |
|
36 | + add_filter('template_include', array($this, 'template_include'), 9); |
|
37 | 37 | |
38 | - foreach ( $this->template_types as $type ) { |
|
39 | - add_filter( "{$type}_template_hierarchy", array( $this, 'template_hierarchy' ) ); |
|
38 | + foreach ($this->template_types as $type) { |
|
39 | + add_filter("{$type}_template_hierarchy", array($this, 'template_hierarchy')); |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | |
43 | 43 | public function disable() { |
44 | 44 | |
45 | - remove_filter( 'template_include', array( $this, 'template_include' ), 9 ); |
|
45 | + remove_filter('template_include', array($this, 'template_include'), 9); |
|
46 | 46 | |
47 | - foreach ( $this->template_types as $type ) { |
|
48 | - remove_filter( "{$type}_template_hierarchy", array( $this, 'template_hierarchy' ) ); |
|
47 | + foreach ($this->template_types as $type) { |
|
48 | + remove_filter("{$type}_template_hierarchy", array($this, 'template_hierarchy')); |
|
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
@@ -54,21 +54,21 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return string[] Array of templates, prepended with Twig versions. |
56 | 56 | */ |
57 | - public function template_hierarchy( $templates ) { |
|
57 | + public function template_hierarchy($templates) { |
|
58 | 58 | |
59 | - $this->type = substr( current_filter(), 0, - 19 ); // Trim '_template_hierarchy' from end. |
|
59 | + $this->type = substr(current_filter(), 0, - 19); // Trim '_template_hierarchy' from end. |
|
60 | 60 | |
61 | 61 | $twig_templates = []; |
62 | 62 | |
63 | - foreach ( $templates as $php_template ) { |
|
63 | + foreach ($templates as $php_template) { |
|
64 | 64 | |
65 | - if ( '.php' === substr( $php_template, strlen( $php_template ) - 4 ) ) { |
|
65 | + if ('.php' === substr($php_template, strlen($php_template) - 4)) { |
|
66 | 66 | |
67 | - $twig_templates[] = substr( $php_template, 0, - 4 ) . '.twig'; |
|
67 | + $twig_templates[] = substr($php_template, 0, - 4) . '.twig'; |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
71 | - return array_merge( $twig_templates, $templates ); |
|
71 | + return array_merge($twig_templates, $templates); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @return string |
78 | 78 | */ |
79 | - public function template_include( $template ) { |
|
79 | + public function template_include($template) { |
|
80 | 80 | |
81 | - return apply_filters( 'meadow_query_template', $template, $this->type ); |
|
81 | + return apply_filters('meadow_query_template', $template, $this->type); |
|
82 | 82 | } |
83 | 83 | } |
@@ -34,39 +34,39 @@ discard block |
||
34 | 34 | |
35 | 35 | public function enable() { |
36 | 36 | |
37 | - add_action( 'template_redirect', array( $this, 'template_redirect' ) ); |
|
37 | + add_action('template_redirect', array($this, 'template_redirect')); |
|
38 | 38 | |
39 | - foreach ( $this->template_types as $type ) { |
|
40 | - add_filter( "{$type}_template", array( $this, 'query_template' ) ); |
|
39 | + foreach ($this->template_types as $type) { |
|
40 | + add_filter("{$type}_template", array($this, 'query_template')); |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | 44 | public function disable() { |
45 | 45 | |
46 | - remove_action( 'template_redirect', array( $this, 'template_redirect' ) ); |
|
46 | + remove_action('template_redirect', array($this, 'template_redirect')); |
|
47 | 47 | |
48 | - foreach ( $this->template_types as $type ) { |
|
49 | - remove_filter( "{$type}_template", array( $this, 'query_template' ) ); |
|
48 | + foreach ($this->template_types as $type) { |
|
49 | + remove_filter("{$type}_template", array($this, 'query_template')); |
|
50 | 50 | } |
51 | 51 | |
52 | - if ( ! empty($this->mime_type) ) { |
|
53 | - remove_filter( "{$this->mime_type[0]}_template", array( $this, 'query_template' ) ); |
|
54 | - remove_filter( "{$this->mime_type[1]}_template", array( $this, 'query_template' ) ); |
|
55 | - remove_filter( "{$this->mime_type[0]}{$this->mime_type[1]}_template", array( $this, 'query_template' ) ); |
|
52 | + if ( ! empty($this->mime_type)) { |
|
53 | + remove_filter("{$this->mime_type[0]}_template", array($this, 'query_template')); |
|
54 | + remove_filter("{$this->mime_type[1]}_template", array($this, 'query_template')); |
|
55 | + remove_filter("{$this->mime_type[0]}{$this->mime_type[1]}_template", array($this, 'query_template')); |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
59 | 59 | public function template_redirect() { |
60 | 60 | |
61 | - if ( is_attachment() ) { |
|
61 | + if (is_attachment()) { |
|
62 | 62 | global $posts; |
63 | 63 | |
64 | - if ( ! empty( $posts ) && isset( $posts[0]->post_mime_type ) ) |
|
65 | - $this->mime_type = explode( '/', $posts[0]->post_mime_type ); |
|
64 | + if ( ! empty($posts) && isset($posts[0]->post_mime_type)) |
|
65 | + $this->mime_type = explode('/', $posts[0]->post_mime_type); |
|
66 | 66 | |
67 | - add_filter( "{$this->mime_type[0]}_template", array( $this, 'query_template' ) ); |
|
68 | - add_filter( "{$this->mime_type[1]}_template", array( $this, 'query_template' ) ); |
|
69 | - add_filter( "{$this->mime_type[0]}{$this->mime_type[1]}_template", array( $this, 'query_template' ) ); |
|
67 | + add_filter("{$this->mime_type[0]}_template", array($this, 'query_template')); |
|
68 | + add_filter("{$this->mime_type[1]}_template", array($this, 'query_template')); |
|
69 | + add_filter("{$this->mime_type[0]}{$this->mime_type[1]}_template", array($this, 'query_template')); |
|
70 | 70 | } |
71 | 71 | } |
72 | 72 | |
@@ -75,21 +75,21 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return string |
77 | 77 | */ |
78 | - public function query_template( $fallback ) { |
|
78 | + public function query_template($fallback) { |
|
79 | 79 | |
80 | - $type = substr( current_filter(), 0, - 9 ); // trim '_template' from end |
|
80 | + $type = substr(current_filter(), 0, - 9); // trim '_template' from end |
|
81 | 81 | $templates = array(); |
82 | 82 | |
83 | - switch ( $type ) { |
|
83 | + switch ($type) { |
|
84 | 84 | case 'embed': |
85 | 85 | |
86 | 86 | $object = get_queried_object(); |
87 | 87 | |
88 | - if ( ! empty( $object->post_type ) ) { |
|
88 | + if ( ! empty($object->post_type)) { |
|
89 | 89 | |
90 | - $post_format = get_post_format( $object ); |
|
90 | + $post_format = get_post_format($object); |
|
91 | 91 | |
92 | - if ( $post_format ) { |
|
92 | + if ($post_format) { |
|
93 | 93 | $templates[] = "embed-{$object->post_type}-{$post_format}.twig"; |
94 | 94 | } |
95 | 95 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | case 'taxonomy': |
104 | 104 | $term = get_queried_object(); |
105 | 105 | |
106 | - if ( $term ) { |
|
106 | + if ($term) { |
|
107 | 107 | $taxonomy = $term->taxonomy; |
108 | 108 | $templates[] = "taxonomy-{$taxonomy}-{$term->slug}.twig"; |
109 | 109 | $templates[] = "taxonomy-{$taxonomy}.twig"; |
@@ -113,17 +113,17 @@ discard block |
||
113 | 113 | break; |
114 | 114 | |
115 | 115 | case 'frontpage': |
116 | - $templates = array( 'front-page.twig' ); |
|
116 | + $templates = array('front-page.twig'); |
|
117 | 117 | break; |
118 | 118 | |
119 | 119 | case 'home': |
120 | - $templates = array( 'home.twig', 'index.twig' ); |
|
120 | + $templates = array('home.twig', 'index.twig'); |
|
121 | 121 | break; |
122 | 122 | |
123 | 123 | case 'single': |
124 | 124 | $object = get_queried_object(); |
125 | 125 | |
126 | - if ( $object ) |
|
126 | + if ($object) |
|
127 | 127 | $templates[] = "single-{$object->post_type}.twig"; |
128 | 128 | |
129 | 129 | $templates[] = 'single.twig'; |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | case 'page': |
133 | 133 | $page_id = get_queried_object_id(); |
134 | 134 | // $template = get_page_template_slug(); |
135 | - $pagename = get_query_var( 'pagename' ); |
|
135 | + $pagename = get_query_var('pagename'); |
|
136 | 136 | |
137 | - if ( ! $pagename && $page_id ) { |
|
137 | + if ( ! $pagename && $page_id) { |
|
138 | 138 | // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object |
139 | 139 | $post = get_queried_object(); |
140 | 140 | $pagename = $post->post_name; |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | // if ( $template && 0 === validate_file( $template ) ) |
145 | 145 | // $templates[] = $template; |
146 | 146 | |
147 | - if ( $pagename ) |
|
147 | + if ($pagename) |
|
148 | 148 | $templates[] = "page-{$pagename}.twig"; |
149 | 149 | |
150 | - if ( $page_id ) |
|
150 | + if ($page_id) |
|
151 | 151 | $templates[] = "page-{$page_id}.twig"; |
152 | 152 | |
153 | 153 | $templates[] = 'page.twig'; |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | case 'tag': |
158 | 158 | $term = get_queried_object(); |
159 | 159 | |
160 | - if ( $term ) { |
|
160 | + if ($term) { |
|
161 | 161 | $templates[] = "{$type}-{$term->slug}.twig"; |
162 | 162 | $templates[] = "{$type}-{$term->term_id}.twig"; |
163 | 163 | } |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | case 'author': |
169 | 169 | $author = get_queried_object(); |
170 | 170 | |
171 | - if ( $author ) { |
|
171 | + if ($author) { |
|
172 | 172 | $templates[] = "author-{$author->user_nicename}.twig"; |
173 | 173 | $templates[] = "author-{$author->ID}.twig"; |
174 | 174 | } |
@@ -177,10 +177,10 @@ discard block |
||
177 | 177 | break; |
178 | 178 | |
179 | 179 | case 'archive': |
180 | - $post_types = array_filter( (array) get_query_var( 'post_type' ) ); |
|
180 | + $post_types = array_filter((array) get_query_var('post_type')); |
|
181 | 181 | |
182 | - if ( count( $post_types ) == 1 ) { |
|
183 | - $post_type = reset( $post_types ); |
|
182 | + if (count($post_types) == 1) { |
|
183 | + $post_type = reset($post_types); |
|
184 | 184 | $templates[] = "archive-{$post_type}.twig"; |
185 | 185 | } |
186 | 186 | |
@@ -188,16 +188,16 @@ discard block |
||
188 | 188 | break; |
189 | 189 | |
190 | 190 | default: |
191 | - $templates = array( "{$type}.twig" ); |
|
191 | + $templates = array("{$type}.twig"); |
|
192 | 192 | } |
193 | 193 | |
194 | - $template = $this->locate_template( $templates ); |
|
194 | + $template = $this->locate_template($templates); |
|
195 | 195 | |
196 | - if ( empty( $template ) ) { |
|
196 | + if (empty($template)) { |
|
197 | 197 | $template = $fallback; |
198 | 198 | } |
199 | 199 | |
200 | - return apply_filters( 'meadow_query_template', $template, $type ); |
|
200 | + return apply_filters('meadow_query_template', $template, $type); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | * |
208 | 208 | * @return string |
209 | 209 | */ |
210 | - public function locate_template( $templates ) { |
|
210 | + public function locate_template($templates) { |
|
211 | 211 | |
212 | - return locate_template( $templates ); |
|
212 | + return locate_template($templates); |
|
213 | 213 | } |
214 | 214 | } |
@@ -11,14 +11,14 @@ discard block |
||
11 | 11 | /** |
12 | 12 | * @param array $values |
13 | 13 | */ |
14 | - public function __construct( $values = array() ) { |
|
14 | + public function __construct($values = array()) { |
|
15 | 15 | |
16 | 16 | global $wp_version; |
17 | 17 | |
18 | 18 | $defaults['twig.options'] = array(); |
19 | 19 | $defaults['twig.directories'] = array(); |
20 | 20 | |
21 | - $defaults['twig.loader'] = function ( $meadow ) { |
|
21 | + $defaults['twig.loader'] = function($meadow) { |
|
22 | 22 | |
23 | 23 | // this needs to be lazy or theme switchers and alike explode it |
24 | 24 | |
@@ -27,12 +27,12 @@ discard block |
||
27 | 27 | $calculated_dirs = array( |
28 | 28 | $stylesheet_dir, |
29 | 29 | $template_dir, |
30 | - plugin_dir_path( __DIR__ ) . 'twig', |
|
30 | + plugin_dir_path(__DIR__) . 'twig', |
|
31 | 31 | ); |
32 | 32 | |
33 | 33 | // enables explicit inheritance from parent theme in child |
34 | - if ( $stylesheet_dir !== $template_dir ) { |
|
35 | - $calculated_dirs[] = dirname( $template_dir ); |
|
34 | + if ($stylesheet_dir !== $template_dir) { |
|
35 | + $calculated_dirs[] = dirname($template_dir); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | $directories = array_unique( |
@@ -42,44 +42,44 @@ discard block |
||
42 | 42 | ) |
43 | 43 | ); |
44 | 44 | |
45 | - return new \Twig_Loader_Filesystem( $directories ); |
|
45 | + return new \Twig_Loader_Filesystem($directories); |
|
46 | 46 | }; |
47 | 47 | |
48 | - $defaults['twig.undefined_function'] = array( __CLASS__, 'undefined_function' ); |
|
49 | - $defaults['twig.undefined_filter'] = array( __CLASS__, 'undefined_filter' ); |
|
48 | + $defaults['twig.undefined_function'] = array(__CLASS__, 'undefined_function'); |
|
49 | + $defaults['twig.undefined_filter'] = array(__CLASS__, 'undefined_filter'); |
|
50 | 50 | |
51 | - $defaults['twig.environment'] = function ( $meadow ) { |
|
52 | - $environment = new \Twig_Environment( $meadow['twig.loader'], $meadow['twig.options'] ); |
|
51 | + $defaults['twig.environment'] = function($meadow) { |
|
52 | + $environment = new \Twig_Environment($meadow['twig.loader'], $meadow['twig.options']); |
|
53 | 53 | $meadow_extension = new Extension(); |
54 | - $environment->addExtension( $meadow_extension ); |
|
55 | - $environment->registerUndefinedFunctionCallback( $meadow['twig.undefined_function'] ); |
|
56 | - $environment->registerUndefinedFilterCallback( $meadow['twig.undefined_filter'] ); |
|
54 | + $environment->addExtension($meadow_extension); |
|
55 | + $environment->registerUndefinedFunctionCallback($meadow['twig.undefined_function']); |
|
56 | + $environment->registerUndefinedFilterCallback($meadow['twig.undefined_filter']); |
|
57 | 57 | |
58 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
58 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
59 | 59 | $debug_extension = new \Twig_Extension_Debug(); |
60 | - $environment->addExtension( $debug_extension ); |
|
60 | + $environment->addExtension($debug_extension); |
|
61 | 61 | $environment->enableDebug(); |
62 | 62 | } |
63 | 63 | |
64 | 64 | return $environment; |
65 | 65 | }; |
66 | 66 | |
67 | - if ( version_compare( rtrim( $wp_version, '-src' ), '4.7', '>=' ) ) { |
|
67 | + if (version_compare(rtrim($wp_version, '-src'), '4.7', '>=')) { |
|
68 | 68 | |
69 | - $defaults['hierarchy'] = function () { |
|
69 | + $defaults['hierarchy'] = function() { |
|
70 | 70 | return new Type_Template_Hierarchy(); |
71 | 71 | }; |
72 | 72 | } else { |
73 | 73 | |
74 | - trigger_error( 'Pre–WP 4.7 implementation of Meadow hierarchy is deprecated and will be removed in 1.0.', E_USER_DEPRECATED ); |
|
74 | + trigger_error('Pre–WP 4.7 implementation of Meadow hierarchy is deprecated and will be removed in 1.0.', E_USER_DEPRECATED); |
|
75 | 75 | |
76 | - $defaults['hierarchy'] = function () { |
|
76 | + $defaults['hierarchy'] = function() { |
|
77 | 77 | return new Template_Hierarchy(); |
78 | 78 | }; |
79 | 79 | } |
80 | 80 | |
81 | 81 | |
82 | - parent::__construct( array_merge( $defaults, $values ) ); |
|
82 | + parent::__construct(array_merge($defaults, $values)); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -89,20 +89,20 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return bool|\Twig_SimpleFunction |
91 | 91 | */ |
92 | - static function undefined_function( $function_name ) { |
|
92 | + static function undefined_function($function_name) { |
|
93 | 93 | |
94 | - if ( function_exists( $function_name ) ) { |
|
94 | + if (function_exists($function_name)) { |
|
95 | 95 | return new \Twig_SimpleFunction( |
96 | 96 | $function_name, |
97 | - function () use ( $function_name ) { |
|
97 | + function() use ($function_name) { |
|
98 | 98 | |
99 | 99 | ob_start(); |
100 | - $return = call_user_func_array( $function_name, func_get_args() ); |
|
100 | + $return = call_user_func_array($function_name, func_get_args()); |
|
101 | 101 | $echo = ob_get_clean(); |
102 | 102 | |
103 | - return empty( $echo ) ? $return : $echo; |
|
103 | + return empty($echo) ? $return : $echo; |
|
104 | 104 | }, |
105 | - array( 'is_safe' => array( 'all' ) ) |
|
105 | + array('is_safe' => array('all')) |
|
106 | 106 | ); |
107 | 107 | } |
108 | 108 | |
@@ -116,15 +116,15 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @return bool|\Twig_SimpleFilter |
118 | 118 | */ |
119 | - static function undefined_filter( $filter_name ) { |
|
119 | + static function undefined_filter($filter_name) { |
|
120 | 120 | |
121 | 121 | return new \Twig_SimpleFilter( |
122 | 122 | $filter_name, |
123 | - function () use ( $filter_name ) { |
|
123 | + function() use ($filter_name) { |
|
124 | 124 | |
125 | - return apply_filters( $filter_name, func_get_arg( 0 ) ); |
|
125 | + return apply_filters($filter_name, func_get_arg(0)); |
|
126 | 126 | }, |
127 | - array( 'is_safe' => array( 'all' ) ) |
|
127 | + array('is_safe' => array('all')) |
|
128 | 128 | ); |
129 | 129 | } |
130 | 130 | |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | /** @var Template_Hierarchy $hierarchy */ |
134 | 134 | $hierarchy = $this['hierarchy']; |
135 | 135 | $hierarchy->enable(); |
136 | - add_filter( 'template_include', array( $this, 'template_include' ) ); |
|
137 | - add_filter( 'get_search_form', array( $this, 'get_search_form' ), 9 ); |
|
136 | + add_filter('template_include', array($this, 'template_include')); |
|
137 | + add_filter('get_search_form', array($this, 'get_search_form'), 9); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | public function disable() { |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | /** @var Template_Hierarchy $hierarchy */ |
143 | 143 | $hierarchy = $this['hierarchy']; |
144 | 144 | $hierarchy->disable(); |
145 | - remove_filter( 'template_include', array( $this, 'template_include' ) ); |
|
146 | - remove_filter( 'get_search_form', array( $this, 'get_search_form' ), 9 ); |
|
145 | + remove_filter('template_include', array($this, 'template_include')); |
|
146 | + remove_filter('get_search_form', array($this, 'get_search_form'), 9); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | * |
152 | 152 | * @return string|bool |
153 | 153 | */ |
154 | - public function template_include( $template ) { |
|
154 | + public function template_include($template) { |
|
155 | 155 | |
156 | - if ( '.twig' === substr( $template, - 5 ) ) { |
|
156 | + if ('.twig' === substr($template, - 5)) { |
|
157 | 157 | /** @var \Twig_Environment $twig */ |
158 | 158 | $twig = $this['twig.environment']; |
159 | 159 | |
160 | - echo $twig->render( basename( $template ), apply_filters( 'meadow_context', array() ) ); |
|
160 | + echo $twig->render(basename($template), apply_filters('meadow_context', array())); |
|
161 | 161 | |
162 | 162 | return false; |
163 | 163 | } |
@@ -170,14 +170,14 @@ discard block |
||
170 | 170 | * |
171 | 171 | * @return string |
172 | 172 | */ |
173 | - public function get_search_form( $form ) { |
|
173 | + public function get_search_form($form) { |
|
174 | 174 | |
175 | 175 | // because first time it's action |
176 | - if ( ! empty( $form ) ) { |
|
176 | + if ( ! empty($form)) { |
|
177 | 177 | /** @var \Twig_Environment $twig */ |
178 | 178 | $twig = $this['twig.environment']; |
179 | 179 | |
180 | - return $twig->render( 'searchform.twig', array() ); |
|
180 | + return $twig->render('searchform.twig', array()); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | return $form; |