@@ -42,13 +42,13 @@ discard block |
||
42 | 42 | $yamlFile = $this->getYamlFile(); |
43 | 43 | $yaml = $this->normalizeYamlValues( $this->normalize( |
44 | 44 | $this->parseYaml( file_get_contents( $yamlFile ), $yamlFile ) |
45 | - )); |
|
46 | - if( !$yaml['disable_config'] ) { |
|
47 | - $config = array_filter( (array) get_option( Config::id(), [] )); |
|
45 | + ) ); |
|
46 | + if( !$yaml[ 'disable_config' ] ) { |
|
47 | + $config = array_filter( (array) get_option( Config::id(), [ ] ) ); |
|
48 | 48 | } |
49 | 49 | return empty( $config ) |
50 | - ? $this->setTimestamp( $yaml, filemtime( $yamlFile )) |
|
51 | - : $this->normalizeYamlValues( $this->normalize( $config )); |
|
50 | + ? $this->setTimestamp( $yaml, filemtime( $yamlFile ) ) |
|
51 | + : $this->normalizeYamlValues( $this->normalize( $config ) ); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -57,15 +57,15 @@ discard block |
||
57 | 57 | public function compile() |
58 | 58 | { |
59 | 59 | $configFile = $this->getCompileDestination(); |
60 | - if( $this->shouldCompile( $configFile )) { |
|
60 | + if( $this->shouldCompile( $configFile ) ) { |
|
61 | 61 | $config = $this->normalizeArray( $this->options ); |
62 | 62 | if( $this->parseError ) { |
63 | 63 | return (object) $config; |
64 | 64 | } |
65 | 65 | file_put_contents( $configFile, sprintf( '<?php // DO NOT MODIFY THIS FILE DIRECTLY!%sreturn (object) %s;', |
66 | 66 | PHP_EOL, |
67 | - $this->parseRawStrings( var_export( $this->setTimestamp( $config ), true )) |
|
68 | - )); |
|
67 | + $this->parseRawStrings( var_export( $this->setTimestamp( $config ), true ) ) |
|
68 | + ) ); |
|
69 | 69 | } |
70 | 70 | return include $configFile; |
71 | 71 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | public function convertArrayToYaml( array $array ) |
77 | 77 | { |
78 | 78 | return !empty( $array ) |
79 | - ? trim( $this->parseRawStrings( $this->dumpYaml( $array ))) |
|
79 | + ? trim( $this->parseRawStrings( $this->dumpYaml( $array ) ) ) |
|
80 | 80 | : ''; |
81 | 81 | } |
82 | 82 | |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | trailingslashit( trailingslashit( $theme->theme_root ) . $theme->template ), |
104 | 104 | trailingslashit( WP_CONTENT_DIR ), |
105 | 105 | trailingslashit( ABSPATH ), |
106 | - trailingslashit( dirname( ABSPATH )), |
|
107 | - trailingslashit( dirname( dirname( ABSPATH ))), |
|
108 | - ]); |
|
106 | + trailingslashit( dirname( ABSPATH ) ), |
|
107 | + trailingslashit( dirname( dirname( ABSPATH ) ) ), |
|
108 | + ] ); |
|
109 | 109 | foreach( (array) $configLocations as $location ) { |
110 | - if( !file_exists( $location . $configYaml ))continue; |
|
110 | + if( !file_exists( $location . $configYaml ) )continue; |
|
111 | 111 | return $location . $configYaml; |
112 | 112 | } |
113 | 113 | return $this->app->path( 'defaults.yml' ); |
@@ -119,10 +119,10 @@ discard block |
||
119 | 119 | public function normalizeArray( array $array ) |
120 | 120 | { |
121 | 121 | array_walk( $array, function( &$value, $key ) { |
122 | - if( !is_numeric( $value ) && is_string( $value )) { |
|
122 | + if( !is_numeric( $value ) && is_string( $value ) ) { |
|
123 | 123 | $value = $this->parseYaml( $value, $key ); |
124 | 124 | if( $this->parseError == $key ) { |
125 | - $value = []; |
|
125 | + $value = [ ]; |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | }); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | public function setTimestamp( array $config, $timestamp = null ) |
148 | 148 | { |
149 | 149 | $timestamp || $timestamp = time(); |
150 | - $config['updated'] = $timestamp; |
|
150 | + $config[ 'updated' ] = $timestamp; |
|
151 | 151 | return $config; |
152 | 152 | } |
153 | 153 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | return wp_parse_args( |
173 | 173 | $config, |
174 | 174 | $this->parseYaml( |
175 | - file_get_contents( $this->app->path( 'defaults.yml' )), |
|
175 | + file_get_contents( $this->app->path( 'defaults.yml' ) ), |
|
176 | 176 | $this->app->path( 'defaults.yml' ) |
177 | 177 | ) |
178 | 178 | ); |
@@ -186,13 +186,13 @@ discard block |
||
186 | 186 | protected function parseRawStrings( $configString ) |
187 | 187 | { |
188 | 188 | $strings = apply_filters( 'pollux/config/raw_strings', static::RAW_STRINGS ); |
189 | - if( empty( $strings )) { |
|
189 | + if( empty( $strings ) ) { |
|
190 | 190 | return $configString; |
191 | 191 | } |
192 | 192 | $pattern = '/(\')((' . implode( '|', $strings ) . ')\(?.+\))(\')/'; |
193 | 193 | return stripslashes( |
194 | 194 | preg_replace_callback( $pattern, function( $matches ) { |
195 | - return str_replace( "''", "'", $matches[2] ); |
|
195 | + return str_replace( "''", "'", $matches[ 2 ] ); |
|
196 | 196 | }, $configString ) |
197 | 197 | ); |
198 | 198 | } |
@@ -211,13 +211,13 @@ discard block |
||
211 | 211 | if( $file ) { |
212 | 212 | $file = sprintf( '<code>%s</code>', $file ); |
213 | 213 | } |
214 | - $this->app->make( 'Notice' )->addError([ |
|
214 | + $this->app->make( 'Notice' )->addError( [ |
|
215 | 215 | sprintf( '<strong>Pollux Error:</strong> Unable to parse config at line %s (near "%s").', |
216 | 216 | $e->getParsedLine(), |
217 | 217 | $e->getSnippet() |
218 | 218 | ), |
219 | 219 | $file |
220 | - ]); |
|
220 | + ] ); |
|
221 | 221 | return $value; |
222 | 222 | } |
223 | 223 | } |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | */ |
229 | 229 | protected function shouldCompile( $configFile ) |
230 | 230 | { |
231 | - if( !file_exists( $configFile )) { |
|
231 | + if( !file_exists( $configFile ) ) { |
|
232 | 232 | return true; |
233 | 233 | } |
234 | 234 | $config = include $configFile; |
@@ -107,7 +107,9 @@ discard block |
||
107 | 107 | trailingslashit( dirname( dirname( ABSPATH ))), |
108 | 108 | ]); |
109 | 109 | foreach( (array) $configLocations as $location ) { |
110 | - if( !file_exists( $location . $configYaml ))continue; |
|
110 | + if( !file_exists( $location . $configYaml )) { |
|
111 | + continue; |
|
112 | + } |
|
111 | 113 | return $location . $configYaml; |
112 | 114 | } |
113 | 115 | return $this->app->path( 'defaults.yml' ); |
@@ -118,7 +120,8 @@ discard block |
||
118 | 120 | */ |
119 | 121 | public function normalizeArray( array $array ) |
120 | 122 | { |
121 | - array_walk( $array, function( &$value, $key ) { |
|
123 | + array_walk( $array, function( &$value, $key ) |
|
124 | + { |
|
122 | 125 | if( !is_numeric( $value ) && is_string( $value )) { |
123 | 126 | $value = $this->parseYaml( $value, $key ); |
124 | 127 | if( $this->parseError == $key ) { |
@@ -134,7 +137,8 @@ discard block |
||
134 | 137 | */ |
135 | 138 | public function normalizeYamlValues( array $array ) |
136 | 139 | { |
137 | - return array_map( function( $value ) { |
|
140 | + return array_map( function( $value ) |
|
141 | + { |
|
138 | 142 | return is_array( $value ) |
139 | 143 | ? $this->convertArrayToYaml( $value ) |
140 | 144 | : $value; |
@@ -191,7 +195,8 @@ discard block |
||
191 | 195 | } |
192 | 196 | $pattern = '/(\')((' . implode( '|', $strings ) . ')\(?.+\))(\')/'; |
193 | 197 | return stripslashes( |
194 | - preg_replace_callback( $pattern, function( $matches ) { |
|
198 | + preg_replace_callback( $pattern, function( $matches ) |
|
199 | + { |
|
195 | 200 | return str_replace( "''", "'", $matches[2] ); |
196 | 201 | }, $configString ) |
197 | 202 | ); |
@@ -22,11 +22,11 @@ discard block |
||
22 | 22 | { |
23 | 23 | $instructions = array_reduce( $this->getInstructionGroups(), function( $html, $metabox ) { |
24 | 24 | $fields = $this->getInstructionFields( $metabox ); |
25 | - if( empty( $fields )) { |
|
25 | + if( empty( $fields ) ) { |
|
26 | 26 | return $html; |
27 | 27 | } |
28 | 28 | return $html . sprintf( '<p><strong>%s</strong></p><pre class="my-sites nav-tab-active misc-pub-section">%s</pre>', |
29 | - $metabox['title'], |
|
29 | + $metabox[ 'title' ], |
|
30 | 30 | $fields |
31 | 31 | ); |
32 | 32 | }); |
@@ -38,10 +38,10 @@ discard block |
||
38 | 38 | */ |
39 | 39 | protected function getInstructionFields( $metabox ) |
40 | 40 | { |
41 | - $skipFields = ['custom_html', 'divider', 'heading']; |
|
42 | - return array_reduce( $metabox['fields'], function( $html, $field ) use( $metabox, $skipFields ) { |
|
43 | - return $this->validate( $field['condition'] ) && !in_array( $field['type'], $skipFields ) |
|
44 | - ? $html . $this->filter( 'instruction', "PostMeta::get('{$field['slug']}');", $field, $metabox ) . PHP_EOL |
|
41 | + $skipFields = [ 'custom_html', 'divider', 'heading' ]; |
|
42 | + return array_reduce( $metabox[ 'fields' ], function( $html, $field ) use( $metabox, $skipFields ) { |
|
43 | + return $this->validate( $field[ 'condition' ] ) && !in_array( $field[ 'type' ], $skipFields ) |
|
44 | + ? $html . $this->filter( 'instruction', "PostMeta::get('{$field[ 'slug' ]}');", $field, $metabox ) . PHP_EOL |
|
45 | 45 | : $html; |
46 | 46 | }); |
47 | 47 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | protected function getInstructionGroups() |
53 | 53 | { |
54 | 54 | return array_filter( $this->metaboxes, function( $metabox ) { |
55 | - return $this->validate( $metabox['condition'] ) |
|
55 | + return $this->validate( $metabox[ 'condition' ] ) |
|
56 | 56 | && $this->hasPostType( $metabox ); |
57 | 57 | }); |
58 | 58 | } |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | return [ |
67 | 67 | 'infodiv' => [ |
68 | 68 | 'context' => 'side', |
69 | - 'fields' => [[ |
|
69 | + 'fields' => [ [ |
|
70 | 70 | 'slug' => '', |
71 | 71 | 'std' => $this->generateInstructions(), |
72 | 72 | 'type' => 'custom_html', |
73 | - ]], |
|
73 | + ] ], |
|
74 | 74 | 'post_types' => $this->getPostTypes(), |
75 | 75 | 'priority' => 'low', |
76 | 76 | 'title' => __( 'How to use in your theme', 'pollux' ), |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | { |
86 | 86 | return $this->filter( 'show/instructions', count( array_filter( $this->metaboxes, function( $metabox ) { |
87 | 87 | return $this->show( false, $metabox ); |
88 | - })) > 0 ); |
|
88 | + }) ) > 0 ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -20,7 +20,8 @@ discard block |
||
20 | 20 | */ |
21 | 21 | protected function generateInstructions() |
22 | 22 | { |
23 | - $instructions = array_reduce( $this->getInstructionGroups(), function( $html, $metabox ) { |
|
23 | + $instructions = array_reduce( $this->getInstructionGroups(), function( $html, $metabox ) |
|
24 | + { |
|
24 | 25 | $fields = $this->getInstructionFields( $metabox ); |
25 | 26 | if( empty( $fields )) { |
26 | 27 | return $html; |
@@ -39,7 +40,8 @@ discard block |
||
39 | 40 | protected function getInstructionFields( $metabox ) |
40 | 41 | { |
41 | 42 | $skipFields = ['custom_html', 'divider', 'heading']; |
42 | - return array_reduce( $metabox['fields'], function( $html, $field ) use( $metabox, $skipFields ) { |
|
43 | + return array_reduce( $metabox['fields'], function( $html, $field ) use( $metabox, $skipFields ) |
|
44 | + { |
|
43 | 45 | return $this->validate( $field['condition'] ) && !in_array( $field['type'], $skipFields ) |
44 | 46 | ? $html . $this->filter( 'instruction', "PostMeta::get('{$field['slug']}');", $field, $metabox ) . PHP_EOL |
45 | 47 | : $html; |
@@ -51,7 +53,8 @@ discard block |
||
51 | 53 | */ |
52 | 54 | protected function getInstructionGroups() |
53 | 55 | { |
54 | - return array_filter( $this->metaboxes, function( $metabox ) { |
|
56 | + return array_filter( $this->metaboxes, function( $metabox ) |
|
57 | + { |
|
55 | 58 | return $this->validate( $metabox['condition'] ) |
56 | 59 | && $this->hasPostType( $metabox ); |
57 | 60 | }); |
@@ -62,7 +65,9 @@ discard block |
||
62 | 65 | */ |
63 | 66 | protected function initInstructions() |
64 | 67 | { |
65 | - if( !$this->showInstructions() )return; |
|
68 | + if( !$this->showInstructions() ) { |
|
69 | + return; |
|
70 | + } |
|
66 | 71 | return [ |
67 | 72 | 'infodiv' => [ |
68 | 73 | 'context' => 'side', |
@@ -83,7 +88,8 @@ discard block |
||
83 | 88 | */ |
84 | 89 | protected function showInstructions() |
85 | 90 | { |
86 | - return $this->filter( 'show/instructions', count( array_filter( $this->metaboxes, function( $metabox ) { |
|
91 | + return $this->filter( 'show/instructions', count( array_filter( $this->metaboxes, function( $metabox ) |
|
92 | + { |
|
87 | 93 | return $this->show( false, $metabox ); |
88 | 94 | })) > 0 ); |
89 | 95 | } |