@@ -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; |
@@ -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' )); |