@@ -31,6 +31,7 @@ discard block |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | + * @param boolean $bool |
|
34 | 35 | * @return bool |
35 | 36 | * @filter rwmb_show |
36 | 37 | */ |
@@ -200,7 +201,6 @@ discard block |
||
200 | 201 | } |
201 | 202 | |
202 | 203 | /** |
203 | - * @param string $id |
|
204 | 204 | * @param string $parentId |
205 | 205 | * @return string |
206 | 206 | */ |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @var array |
19 | 19 | */ |
20 | - public $metaboxes = []; |
|
20 | + public $metaboxes = [ ]; |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * {@inheritdoc} |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | { |
27 | 27 | $this->normalize(); |
28 | 28 | |
29 | - add_filter( 'rwmb_show', [$this, 'isVisible'], 10, 2 ); |
|
30 | - add_filter( 'rwmb_meta_boxes', [$this, 'register'] ); |
|
29 | + add_filter( 'rwmb_show', [ $this, 'isVisible' ], 10, 2 ); |
|
30 | + add_filter( 'rwmb_meta_boxes', [ $this, 'register' ] ); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -37,11 +37,11 @@ discard block |
||
37 | 37 | public function isVisible( $bool, array $metabox ) |
38 | 38 | { |
39 | 39 | if( defined( 'DOING_AJAX' ) |
40 | - || !isset( $metabox['condition'] ) |
|
41 | - || !$this->hasPostType( $metabox )) { |
|
40 | + || !isset( $metabox[ 'condition' ] ) |
|
41 | + || !$this->hasPostType( $metabox ) ) { |
|
42 | 42 | return $bool; |
43 | 43 | } |
44 | - return $this->verifyMetaBoxCondition( $metabox['condition'] ); |
|
44 | + return $this->verifyMetaBoxCondition( $metabox[ 'condition' ] ); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function register() |
52 | 52 | { |
53 | - if( current_user_can( 'switch_themes' )) { |
|
53 | + if( current_user_can( 'switch_themes' ) ) { |
|
54 | 54 | $this->addInstructions(); |
55 | 55 | } |
56 | 56 | $metaboxes = func_num_args() |
57 | - ? $this->toArray( func_get_arg(0) ) |
|
58 | - : []; |
|
57 | + ? $this->toArray( func_get_arg( 0 ) ) |
|
58 | + : [ ]; |
|
59 | 59 | return array_merge( $metaboxes, $this->metaboxes ); |
60 | 60 | } |
61 | 61 | |
@@ -80,18 +80,18 @@ discard block |
||
80 | 80 | { |
81 | 81 | if( !count( array_filter( $this->metaboxes, function( $metabox ) { |
82 | 82 | return $this->isVisible( false, $metabox ); |
83 | - })))return; |
|
84 | - $this->metaboxes[] = [ |
|
83 | + }) ) )return; |
|
84 | + $this->metaboxes[ ] = [ |
|
85 | 85 | 'id' => 'infodiv', |
86 | 86 | 'post_types' => $this->getPostTypes(), |
87 | 87 | 'title' => __( 'How to use in your theme', 'pollux' ), |
88 | 88 | 'context' => 'side', |
89 | 89 | 'priority' => 'low', |
90 | - 'fields' => [[ |
|
90 | + 'fields' => [ [ |
|
91 | 91 | 'slug' => '', |
92 | 92 | 'std' => $this->generateInstructions(), |
93 | 93 | 'type' => 'custom_html', |
94 | - ]], |
|
94 | + ] ], |
|
95 | 95 | ]; |
96 | 96 | } |
97 | 97 | |
@@ -101,12 +101,12 @@ discard block |
||
101 | 101 | protected function generateInstructions() |
102 | 102 | { |
103 | 103 | return array_reduce( $this->getInstructions(), function( $html, $metabox ) { |
104 | - $fields = array_reduce( array_column( $metabox['fields'], 'slug' ), function( $html, $slug ) use( $metabox ) { |
|
104 | + $fields = array_reduce( array_column( $metabox[ 'fields' ], 'slug' ), function( $html, $slug ) use( $metabox ) { |
|
105 | 105 | $hook = sprintf( 'pollux/%s/instruction', $this->getClassname() ); |
106 | - return $html . apply_filters( $hook, "PostMeta::get('{$slug}');", $slug, $metabox['slug'] ) . PHP_EOL; |
|
106 | + return $html . apply_filters( $hook, "PostMeta::get('{$slug}');", $slug, $metabox[ 'slug' ] ) . PHP_EOL; |
|
107 | 107 | }); |
108 | 108 | return $html . sprintf( '<p><strong>%s</strong></p><pre class="my-sites nav-tab-active misc-pub-section">%s</pre>', |
109 | - $metabox['title'], |
|
109 | + $metabox[ 'title' ], |
|
110 | 110 | $fields |
111 | 111 | ); |
112 | 112 | }); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | protected function getInstructions() |
119 | 119 | { |
120 | 120 | return array_filter( $this->metaboxes, function( $metabox ) { |
121 | - return $this->verifyMetaBoxCondition( $metabox['condition'] ) |
|
121 | + return $this->verifyMetaBoxCondition( $metabox[ 'condition' ] ) |
|
122 | 122 | && $this->hasPostType( $metabox ); |
123 | 123 | }); |
124 | 124 | } |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | */ |
129 | 129 | protected function getPostId() |
130 | 130 | { |
131 | - if( !( $postId = filter_input( INPUT_GET, 'post' ))) { |
|
131 | + if( !( $postId = filter_input( INPUT_GET, 'post' ) ) ) { |
|
132 | 132 | $postId = filter_input( INPUT_POST, 'post_ID' ); |
133 | 133 | } |
134 | 134 | return intval( $postId ); |
@@ -141,10 +141,10 @@ discard block |
||
141 | 141 | { |
142 | 142 | return array_unique( iterator_to_array( |
143 | 143 | new RecursiveIteratorIterator( |
144 | - new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' )) |
|
144 | + new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' ) ) |
|
145 | 145 | ), |
146 | 146 | false |
147 | - )); |
|
147 | + ) ); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | */ |
153 | 153 | protected function hasPostType( array $metabox ) |
154 | 154 | { |
155 | - if( !isset( $metabox['post_types'] )) { |
|
155 | + if( !isset( $metabox[ 'post_types' ] ) ) { |
|
156 | 156 | return true; |
157 | 157 | } |
158 | - return in_array( get_post_type( $this->getPostId() ), $metabox['post_types'] ); |
|
158 | + return in_array( get_post_type( $this->getPostId() ), $metabox[ 'post_types' ] ); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -163,15 +163,15 @@ discard block |
||
163 | 163 | */ |
164 | 164 | protected function normalize() |
165 | 165 | { |
166 | - foreach( $this->app->config['meta_boxes'] as $id => $metabox ) { |
|
166 | + foreach( $this->app->config[ 'meta_boxes' ] as $id => $metabox ) { |
|
167 | 167 | $defaults = [ |
168 | - 'condition' => [], |
|
169 | - 'fields' => [], |
|
168 | + 'condition' => [ ], |
|
169 | + 'fields' => [ ], |
|
170 | 170 | 'id' => $id, |
171 | - 'post_types' => [], |
|
171 | + 'post_types' => [ ], |
|
172 | 172 | 'slug' => $id, |
173 | 173 | ]; |
174 | - $this->metaboxes[] = $this->setDependencies( |
|
174 | + $this->metaboxes[ ] = $this->setDependencies( |
|
175 | 175 | $this->normalizeThis( $metabox, $defaults, $id ) |
176 | 176 | ); |
177 | 177 | } |
@@ -184,9 +184,9 @@ discard block |
||
184 | 184 | protected function normalizeCondition( $conditions ) |
185 | 185 | { |
186 | 186 | $conditions = $this->toArray( $conditions ); |
187 | - if( count( array_filter( array_keys( $conditions ), 'is_string' )) == 0 ) { |
|
187 | + if( count( array_filter( array_keys( $conditions ), 'is_string' ) ) == 0 ) { |
|
188 | 188 | foreach( $conditions as $key ) { |
189 | - $conditions[str_replace( '!', '', $key )] = substr( $key, 0, 1 ) == '!' ? 0 : 1; |
|
189 | + $conditions[ str_replace( '!', '', $key ) ] = substr( $key, 0, 1 ) == '!' ? 0 : 1; |
|
190 | 190 | } |
191 | 191 | $conditions = array_filter( $conditions, function( $key ) { |
192 | 192 | return !is_numeric( $key ); |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | $hook = sprintf( 'pollux/%s/conditions', $this->getClassname() ); |
196 | 196 | return array_intersect_key( |
197 | 197 | $conditions, |
198 | - array_flip( apply_filters( $hook, static::CONDITIONS )) |
|
198 | + array_flip( apply_filters( $hook, static::CONDITIONS ) ) |
|
199 | 199 | ); |
200 | 200 | } |
201 | 201 | |
@@ -217,8 +217,8 @@ discard block |
||
217 | 217 | protected function normalizeFields( array $fields, array $data, $parentId ) |
218 | 218 | { |
219 | 219 | return array_map( function( $id, $field ) use( $parentId ) { |
220 | - $defaults = [ |
|
221 | - 'attributes' => [], |
|
220 | + $defaults = [ |
|
221 | + 'attributes' => [ ], |
|
222 | 222 | // 'condition' => [], |
223 | 223 | 'depends' => '', |
224 | 224 | 'id' => $id, |
@@ -253,11 +253,11 @@ discard block |
||
253 | 253 | */ |
254 | 254 | protected function setDependencies( array $metabox ) |
255 | 255 | { |
256 | - $fields = &$metabox['fields']; |
|
256 | + $fields = &$metabox[ 'fields' ]; |
|
257 | 257 | $depends = array_column( $fields, 'depends' ); |
258 | 258 | array_walk( $depends, function( $value, $index ) use( &$fields ) { |
259 | - if( empty( $value ))return; |
|
260 | - $fields[$index]['attributes']['data-depends'] = $value; |
|
259 | + if( empty( $value ) )return; |
|
260 | + $fields[ $index ][ 'attributes' ][ 'data-depends' ] = $value; |
|
261 | 261 | }); |
262 | 262 | return $metabox; |
263 | 263 | } |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | */ |
305 | 305 | protected function validateIsFrontPage( $value ) |
306 | 306 | { |
307 | - return $value == ( $this->getPostId() == get_option( 'page_on_front' )); |
|
307 | + return $value == ( $this->getPostId() == get_option( 'page_on_front' ) ); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | */ |
314 | 314 | protected function validateIsHome( $value ) |
315 | 315 | { |
316 | - return $value == ( $this->getPostId() == get_option( 'page_for_posts' )); |
|
316 | + return $value == ( $this->getPostId() == get_option( 'page_for_posts' ) ); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | */ |
323 | 323 | protected function validateIsPageTemplate( $value ) |
324 | 324 | { |
325 | - return basename( get_page_template_slug( $this->getPostId() )) == $value; |
|
325 | + return basename( get_page_template_slug( $this->getPostId() ) ) == $value; |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -64,7 +64,8 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function verifyMetaBoxCondition( array $conditions ) |
66 | 66 | { |
67 | - array_walk( $conditions, function( &$value, $key ) { |
|
67 | + array_walk( $conditions, function( &$value, $key ) |
|
68 | + { |
|
68 | 69 | $method = $this->app->buildMethodName( $key, 'validate' ); |
69 | 70 | $value = method_exists( $this, $method ) |
70 | 71 | ? $this->$method( $value ) |
@@ -78,9 +79,12 @@ discard block |
||
78 | 79 | */ |
79 | 80 | protected function addInstructions() |
80 | 81 | { |
81 | - if( !count( array_filter( $this->metaboxes, function( $metabox ) { |
|
82 | + if( !count( array_filter( $this->metaboxes, function( $metabox ) |
|
83 | + { |
|
82 | 84 | return $this->isVisible( false, $metabox ); |
83 | - })))return; |
|
85 | + }))) { |
|
86 | + return; |
|
87 | + } |
|
84 | 88 | $this->metaboxes[] = [ |
85 | 89 | 'id' => 'infodiv', |
86 | 90 | 'post_types' => $this->getPostTypes(), |
@@ -100,8 +104,10 @@ discard block |
||
100 | 104 | */ |
101 | 105 | protected function generateInstructions() |
102 | 106 | { |
103 | - return array_reduce( $this->getInstructions(), function( $html, $metabox ) { |
|
104 | - $fields = array_reduce( array_column( $metabox['fields'], 'slug' ), function( $html, $slug ) use( $metabox ) { |
|
107 | + return array_reduce( $this->getInstructions(), function( $html, $metabox ) |
|
108 | + { |
|
109 | + $fields = array_reduce( array_column( $metabox['fields'], 'slug' ), function( $html, $slug ) use( $metabox ) |
|
110 | + { |
|
105 | 111 | $hook = sprintf( 'pollux/%s/instruction', $this->getClassname() ); |
106 | 112 | return $html . apply_filters( $hook, "PostMeta::get('{$slug}');", $slug, $metabox['slug'] ) . PHP_EOL; |
107 | 113 | }); |
@@ -117,7 +123,8 @@ discard block |
||
117 | 123 | */ |
118 | 124 | protected function getInstructions() |
119 | 125 | { |
120 | - return array_filter( $this->metaboxes, function( $metabox ) { |
|
126 | + return array_filter( $this->metaboxes, function( $metabox ) |
|
127 | + { |
|
121 | 128 | return $this->verifyMetaBoxCondition( $metabox['condition'] ) |
122 | 129 | && $this->hasPostType( $metabox ); |
123 | 130 | }); |
@@ -188,7 +195,8 @@ discard block |
||
188 | 195 | foreach( $conditions as $key ) { |
189 | 196 | $conditions[str_replace( '!', '', $key )] = substr( $key, 0, 1 ) == '!' ? 0 : 1; |
190 | 197 | } |
191 | - $conditions = array_filter( $conditions, function( $key ) { |
|
198 | + $conditions = array_filter( $conditions, function( $key ) |
|
199 | + { |
|
192 | 200 | return !is_numeric( $key ); |
193 | 201 | }, ARRAY_FILTER_USE_KEY ); |
194 | 202 | } |
@@ -216,7 +224,8 @@ discard block |
||
216 | 224 | */ |
217 | 225 | protected function normalizeFields( array $fields, array $data, $parentId ) |
218 | 226 | { |
219 | - return array_map( function( $id, $field ) use( $parentId ) { |
|
227 | + return array_map( function( $id, $field ) use( $parentId ) |
|
228 | + { |
|
220 | 229 | $defaults = [ |
221 | 230 | 'attributes' => [], |
222 | 231 | // 'condition' => [], |
@@ -255,8 +264,11 @@ discard block |
||
255 | 264 | { |
256 | 265 | $fields = &$metabox['fields']; |
257 | 266 | $depends = array_column( $fields, 'depends' ); |
258 | - array_walk( $depends, function( $value, $index ) use( &$fields ) { |
|
259 | - if( empty( $value ))return; |
|
267 | + array_walk( $depends, function( $value, $index ) use( &$fields ) |
|
268 | + { |
|
269 | + if( empty( $value )) { |
|
270 | + return; |
|
271 | + } |
|
260 | 272 | $fields[$index]['attributes']['data-depends'] = $value; |
261 | 273 | }); |
262 | 274 | return $metabox; |
@@ -28,11 +28,11 @@ discard block |
||
28 | 28 | { |
29 | 29 | $configFile = $this->getFile(); |
30 | 30 | $configYaml = $this->getYaml(); |
31 | - if( $this->shouldGenerate( $configYaml )) { |
|
31 | + if( $this->shouldGenerate( $configYaml ) ) { |
|
32 | 32 | file_put_contents( $configFile, sprintf( '<?php // DO NOT MODIFY THIS FILE DIRECTLY!%sreturn %s;', |
33 | 33 | PHP_EOL, |
34 | 34 | $this->parseYaml( $configYaml ) |
35 | - )); |
|
35 | + ) ); |
|
36 | 36 | } |
37 | 37 | return include $configFile; |
38 | 38 | } |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | public function getFile( $filename = 'pollux-config.php' ) |
44 | 44 | { |
45 | 45 | $filename = apply_filters( 'pollux/config/dist/file', $filename ); |
46 | - $storagePath = trailingslashit( apply_filters( 'pollux/config/dist/location', WP_CONTENT_DIR )); |
|
47 | - if( !is_dir( $storagePath )) { |
|
46 | + $storagePath = trailingslashit( apply_filters( 'pollux/config/dist/location', WP_CONTENT_DIR ) ); |
|
47 | + if( !is_dir( $storagePath ) ) { |
|
48 | 48 | mkdir( $storagePath, 0775 ); |
49 | 49 | } |
50 | 50 | return sprintf( '%s%s', $storagePath, $filename ); |
@@ -62,11 +62,11 @@ discard block |
||
62 | 62 | trailingslashit( trailingslashit( $theme->theme_root ) . $theme->template ), |
63 | 63 | trailingslashit( WP_CONTENT_DIR ), |
64 | 64 | trailingslashit( ABSPATH ), |
65 | - trailingslashit( dirname( ABSPATH )), |
|
66 | - trailingslashit( dirname( dirname( ABSPATH ))), |
|
67 | - ]); |
|
65 | + trailingslashit( dirname( ABSPATH ) ), |
|
66 | + trailingslashit( dirname( dirname( ABSPATH ) ) ), |
|
67 | + ] ); |
|
68 | 68 | foreach( (array) $configLocations as $location ) { |
69 | - if( !file_exists( $location . $configYaml ))continue; |
|
69 | + if( !file_exists( $location . $configYaml ) )continue; |
|
70 | 70 | return $location . $configYaml; |
71 | 71 | } |
72 | 72 | return $this->app->path( 'defaults.yml' ); |
@@ -79,10 +79,10 @@ discard block |
||
79 | 79 | public function parseYaml( $yamlFile ) |
80 | 80 | { |
81 | 81 | $config = wp_parse_args( |
82 | - Yaml::parse( file_get_contents( $yamlFile )), |
|
83 | - Yaml::parse( file_get_contents( $this->app->path( 'defaults.yml' ))) |
|
82 | + Yaml::parse( file_get_contents( $yamlFile ) ), |
|
83 | + Yaml::parse( file_get_contents( $this->app->path( 'defaults.yml' ) ) ) |
|
84 | 84 | ); |
85 | - return $this->parseRawStrings( var_export( $config, true )); |
|
85 | + return $this->parseRawStrings( var_export( $config, true ) ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | protected function shouldGenerate( $configYaml ) |
105 | 105 | { |
106 | 106 | $configFile = $this->getFile(); |
107 | - if( !file_exists( $configFile )) { |
|
107 | + if( !file_exists( $configFile ) ) { |
|
108 | 108 | return true; |
109 | 109 | } |
110 | 110 | return filemtime( $configYaml ) >= filemtime( $configFile ); |
@@ -66,7 +66,9 @@ |
||
66 | 66 | trailingslashit( dirname( dirname( ABSPATH ))), |
67 | 67 | ]); |
68 | 68 | foreach( (array) $configLocations as $location ) { |
69 | - if( !file_exists( $location . $configYaml ))continue; |
|
69 | + if( !file_exists( $location . $configYaml )) { |
|
70 | + continue; |
|
71 | + } |
|
70 | 72 | return $location . $configYaml; |
71 | 73 | } |
72 | 74 | return $this->app->path( 'defaults.yml' ); |
@@ -39,14 +39,14 @@ discard block |
||
39 | 39 | |
40 | 40 | $this->normalize(); |
41 | 41 | |
42 | - add_action( 'admin_menu', [$this, 'addPage'] ); |
|
43 | - add_action( 'pollux/settings/init', [$this, 'addSubmitMetaBox'] ); |
|
44 | - add_action( 'current_screen', [$this, 'register'] ); |
|
45 | - add_action( 'admin_menu', [$this, 'registerSetting'] ); |
|
46 | - add_action( 'pollux/settings/init', [$this, 'reset'] ); |
|
47 | - add_action( "admin_footer-toplevel_page_{$this->id}", [$this, 'renderFooterScript'] ); |
|
48 | - add_filter( 'pollux/settings/instruction', [$this, 'filterInstruction'], 10, 3 ); |
|
49 | - add_filter( 'wp_redirect', [$this, 'filterRedirectOnSave'] ); |
|
42 | + add_action( 'admin_menu', [ $this, 'addPage' ] ); |
|
43 | + add_action( 'pollux/settings/init', [ $this, 'addSubmitMetaBox' ] ); |
|
44 | + add_action( 'current_screen', [ $this, 'register' ] ); |
|
45 | + add_action( 'admin_menu', [ $this, 'registerSetting' ] ); |
|
46 | + add_action( 'pollux/settings/init', [ $this, 'reset' ] ); |
|
47 | + add_action( "admin_footer-toplevel_page_{$this->id}", [ $this, 'renderFooterScript' ] ); |
|
48 | + add_filter( 'pollux/settings/instruction', [ $this, 'filterInstruction' ], 10, 3 ); |
|
49 | + add_filter( 'wp_redirect', [ $this, 'filterRedirectOnSave' ] ); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | __( 'Site Settings', 'pollux' ), |
61 | 61 | 'edit_theme_options', |
62 | 62 | $this->id, |
63 | - [$this, 'renderPage'], |
|
63 | + [ $this, 'renderPage' ], |
|
64 | 64 | 'dashicons-screenoptions', |
65 | 65 | 1313 |
66 | - ])); |
|
66 | + ] ) ); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | call_user_func_array( 'add_meta_box', apply_filters( 'pollux/settings/metabox/submit', [ |
76 | 76 | 'submitdiv', |
77 | 77 | __( 'Save Settings', 'pollux' ), |
78 | - [ $this, 'renderSubmitMetaBox'], |
|
78 | + [ $this, 'renderSubmitMetaBox' ], |
|
79 | 79 | $this->hook, |
80 | 80 | 'side', |
81 | 81 | 'high', |
82 | - ])); |
|
82 | + ] ) ); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -102,13 +102,13 @@ discard block |
||
102 | 102 | public function filterRedirectOnSave( $location ) |
103 | 103 | { |
104 | 104 | if( strpos( $location, 'settings-updated=true' ) === false |
105 | - || strpos( $location, sprintf( 'page=%s', $this->id )) === false ) { |
|
105 | + || strpos( $location, sprintf( 'page=%s', $this->id ) ) === false ) { |
|
106 | 106 | return $location; |
107 | 107 | } |
108 | - return add_query_arg([ |
|
108 | + return add_query_arg( [ |
|
109 | 109 | 'page' => $this->id, |
110 | 110 | 'settings-updated' => 'true', |
111 | - ], admin_url( 'admin.php' )); |
|
111 | + ], admin_url( 'admin.php' ) ); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function filterSavedSettings( $settings ) |
120 | 120 | { |
121 | - if( is_null( $settings )) { |
|
122 | - $settings = []; |
|
121 | + if( is_null( $settings ) ) { |
|
122 | + $settings = [ ]; |
|
123 | 123 | } |
124 | 124 | return apply_filters( 'pollux/settings/save', $settings ); |
125 | 125 | } |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | add_screen_option( 'layout_columns', [ |
138 | 138 | 'max' => 2, |
139 | 139 | 'default' => 2, |
140 | - ]); |
|
140 | + ] ); |
|
141 | 141 | do_action( 'pollux/settings/init' ); |
142 | 142 | } |
143 | 143 | |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | */ |
148 | 148 | public function registerSetting() |
149 | 149 | { |
150 | - register_setting( $this->id, $this->id, [$this, 'filterSavedSettings'] ); |
|
150 | + register_setting( $this->id, $this->id, [ $this, 'filterSavedSettings' ] ); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | 'confirm' => __( 'Are you sure want to do this?', 'pollux' ), |
161 | 161 | 'hook' => $this->hook, |
162 | 162 | 'id' => $this->id, |
163 | - ]); |
|
163 | + ] ); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | 'columns' => get_current_screen()->get_columns(), |
174 | 174 | 'id' => $this->id, |
175 | 175 | 'title' => __( 'Site Settings', 'pollux' ), |
176 | - ]); |
|
176 | + ] ); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -189,9 +189,9 @@ discard block |
||
189 | 189 | ]; |
190 | 190 | $this->render( 'settings/submit', [ |
191 | 191 | 'reset' => __( 'Reset Settings', 'pollux' ), |
192 | - 'reset_url' => esc_url( add_query_arg( $query, admin_url( 'admin.php' ))), |
|
192 | + 'reset_url' => esc_url( add_query_arg( $query, admin_url( 'admin.php' ) ) ), |
|
193 | 193 | 'submit' => get_submit_button( __( 'Save', 'pollux' ), 'primary', 'submit', false ), |
194 | - ]); |
|
194 | + ] ); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -203,11 +203,11 @@ discard block |
||
203 | 203 | if( filter_input( INPUT_GET, 'page' ) !== $this->id |
204 | 204 | || filter_input( INPUT_GET, 'action' ) !== 'reset' |
205 | 205 | )return; |
206 | - if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook )) { |
|
206 | + if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook ) ) { |
|
207 | 207 | update_option( $this->id, $this->getDefaults() ); |
208 | 208 | return add_settings_error( $this->id, 'reset', __( 'Settings reset to defaults.', 'pollux' ), 'updated' ); |
209 | 209 | } |
210 | - add_settings_error( $this->id, 'reset', __( 'Failed to reset settings. Please refresh the page and try again.', 'pollux' )); |
|
210 | + add_settings_error( $this->id, 'reset', __( 'Failed to reset settings. Please refresh the page and try again.', 'pollux' ) ); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | protected function filterArrayByKey( array $array, $key ) |
218 | 218 | { |
219 | 219 | return array_filter( $array, function( $value ) use( $key ) { |
220 | - return !empty( $value[$key] ); |
|
220 | + return !empty( $value[ $key ] ); |
|
221 | 221 | }); |
222 | 222 | } |
223 | 223 | |
@@ -230,11 +230,11 @@ discard block |
||
230 | 230 | |
231 | 231 | array_walk( $metaboxes, function( &$metabox ) { |
232 | 232 | $fields = array_map( function( $field ) { |
233 | - $field = wp_parse_args( $field, ['std' => ''] ); |
|
234 | - return [$field['slug'] => $field['std']]; |
|
235 | - }, $this->filterArrayByKey( $metabox['fields'], 'slug' )); |
|
233 | + $field = wp_parse_args( $field, [ 'std' => '' ] ); |
|
234 | + return [ $field[ 'slug' ] => $field[ 'std' ] ]; |
|
235 | + }, $this->filterArrayByKey( $metabox[ 'fields' ], 'slug' ) ); |
|
236 | 236 | $metabox = [ |
237 | - $metabox['slug'] => call_user_func_array( 'array_merge', $fields ), |
|
237 | + $metabox[ 'slug' ] => call_user_func_array( 'array_merge', $fields ), |
|
238 | 238 | ]; |
239 | 239 | }); |
240 | 240 | return call_user_func_array( 'array_merge', $metaboxes ); |
@@ -245,14 +245,14 @@ discard block |
||
245 | 245 | */ |
246 | 246 | protected function normalize() |
247 | 247 | { |
248 | - foreach( $this->app->config['settings'] as $id => $metabox ) { |
|
248 | + foreach( $this->app->config[ 'settings' ] as $id => $metabox ) { |
|
249 | 249 | $defaults = [ |
250 | - 'condition' => [], |
|
251 | - 'fields' => [], |
|
250 | + 'condition' => [ ], |
|
251 | + 'fields' => [ ], |
|
252 | 252 | 'id' => $id, |
253 | 253 | 'slug' => $id, |
254 | 254 | ]; |
255 | - $this->metaboxes[] = $this->setDependencies( |
|
255 | + $this->metaboxes[ ] = $this->setDependencies( |
|
256 | 256 | $this->normalizeThis( $metabox, $defaults, $id ) |
257 | 257 | ); |
258 | 258 | } |
@@ -265,10 +265,10 @@ discard block |
||
265 | 265 | */ |
266 | 266 | protected function normalizeFieldName( $name, array $data, $parentId ) |
267 | 267 | { |
268 | - if( !empty( $name )) { |
|
268 | + if( !empty( $name ) ) { |
|
269 | 269 | return $name; |
270 | 270 | } |
271 | - $name = str_replace( sprintf( '%s-%s-', $this->id, $parentId ), '', $data['id'] ); |
|
271 | + $name = str_replace( sprintf( '%s-%s-', $this->id, $parentId ), '', $data[ 'id' ] ); |
|
272 | 272 | return sprintf( '%s[%s][%s]', $this->id, $parentId, $name ); |
273 | 273 | } |
274 | 274 |
@@ -130,7 +130,9 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function register() |
132 | 132 | { |
133 | - if( $this->app->screen()->id != $this->hook )return; |
|
133 | + if( $this->app->screen()->id != $this->hook ) { |
|
134 | + return; |
|
135 | + } |
|
134 | 136 | foreach( parent::register() as $metabox ) { |
135 | 137 | new SettingsMetaBox( $metabox ); |
136 | 138 | } |
@@ -202,7 +204,9 @@ discard block |
||
202 | 204 | { |
203 | 205 | if( filter_input( INPUT_GET, 'page' ) !== $this->id |
204 | 206 | || filter_input( INPUT_GET, 'action' ) !== 'reset' |
205 | - )return; |
|
207 | + ) { |
|
208 | + return; |
|
209 | + } |
|
206 | 210 | if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook )) { |
207 | 211 | update_option( $this->id, $this->getDefaults() ); |
208 | 212 | return add_settings_error( $this->id, 'reset', __( 'Settings reset to defaults.', 'pollux' ), 'updated' ); |
@@ -216,7 +220,8 @@ discard block |
||
216 | 220 | */ |
217 | 221 | protected function filterArrayByKey( array $array, $key ) |
218 | 222 | { |
219 | - return array_filter( $array, function( $value ) use( $key ) { |
|
223 | + return array_filter( $array, function( $value ) use( $key ) |
|
224 | + { |
|
220 | 225 | return !empty( $value[$key] ); |
221 | 226 | }); |
222 | 227 | } |
@@ -228,8 +233,10 @@ discard block |
||
228 | 233 | { |
229 | 234 | $metaboxes = $this->filterArrayByKey( $this->metaboxes, 'slug' ); |
230 | 235 | |
231 | - array_walk( $metaboxes, function( &$metabox ) { |
|
232 | - $fields = array_map( function( $field ) { |
|
236 | + array_walk( $metaboxes, function( &$metabox ) |
|
237 | + { |
|
238 | + $fields = array_map( function( $field ) |
|
239 | + { |
|
233 | 240 | $field = wp_parse_args( $field, ['std' => ''] ); |
234 | 241 | return [$field['slug'] => $field['std']]; |
235 | 242 | }, $this->filterArrayByKey( $metabox['fields'], 'slug' )); |
@@ -15,7 +15,7 @@ |
||
15 | 15 | /** |
16 | 16 | * @var string |
17 | 17 | */ |
18 | - CONST ID = 'pollux_settings'; |
|
18 | + const ID = 'pollux_settings'; |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var string |