@@ -21,7 +21,8 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function validate( array $conditions ) |
23 | 23 | { |
24 | - array_walk( $conditions, function( &$value, $key ) { |
|
24 | + array_walk( $conditions, function( &$value, $key ) |
|
25 | + { |
|
25 | 26 | $method = ( new Helper )->buildMethodName( $key, 'validate' ); |
26 | 27 | $value = method_exists( $this, $method ) |
27 | 28 | ? $this->$method( $value ) |
@@ -41,7 +42,8 @@ discard block |
||
41 | 42 | foreach( $conditions as $key ) { |
42 | 43 | $conditions[str_replace( '!', '', $key )] = substr( $key, 0, 1 ) == '!' ? 0 : 1; |
43 | 44 | } |
44 | - $conditions = array_filter( $conditions, function( $key ) { |
|
45 | + $conditions = array_filter( $conditions, function( $key ) |
|
46 | + { |
|
45 | 47 | return !is_numeric( $key ); |
46 | 48 | }, ARRAY_FILTER_USE_KEY ); |
47 | 49 | } |
@@ -12,7 +12,9 @@ |
||
12 | 12 | */ |
13 | 13 | public function get( $metaKey, array $args = [] ) |
14 | 14 | { |
15 | - if( empty( $metaKey ))return; |
|
15 | + if( empty( $metaKey )) { |
|
16 | + return; |
|
17 | + } |
|
16 | 18 | |
17 | 19 | $args = $this->normalize( $args ); |
18 | 20 | $metaKey = $this->buildMetaKey( $metaKey, $args['prefix'] ); |
@@ -55,7 +55,8 @@ discard block |
||
55 | 55 | public function filterBeforeInstructions() |
56 | 56 | { |
57 | 57 | return sprintf( '<pre class="my-sites nav-tab-active misc-pub-section">%s</pre>', |
58 | - array_reduce( ['title', 'content', 'featured'], function( $instructions, $id ) { |
|
58 | + array_reduce( ['title', 'content', 'featured'], function( $instructions, $id ) |
|
59 | + { |
|
59 | 60 | return $instructions . $this->filterInstruction( null, ['slug' => $id], ['slug' => $this->getPostType()] ) . PHP_EOL; |
60 | 61 | }) |
61 | 62 | ); |
@@ -100,7 +101,9 @@ discard block |
||
100 | 101 | */ |
101 | 102 | public function registerFeaturedImageMetaBox() |
102 | 103 | { |
103 | - if( !current_user_can( 'upload_files' ))return; |
|
104 | + if( !current_user_can( 'upload_files' )) { |
|
105 | + return; |
|
106 | + } |
|
104 | 107 | add_meta_box( 'postimagediv', __( 'Featured Image', 'pollux' ), [$this, 'renderFeaturedImageMetaBox'], null, 'side', 'low' ); |
105 | 108 | } |
106 | 109 | |
@@ -156,7 +159,9 @@ discard block |
||
156 | 159 | public function renderPage() |
157 | 160 | { |
158 | 161 | $type = $this->getPostType(); |
159 | - if( empty( $type ))return; |
|
162 | + if( empty( $type )) { |
|
163 | + return; |
|
164 | + } |
|
160 | 165 | $labels = get_post_type_labels( get_post_type_object( $type )); |
161 | 166 | $this->render( 'archive/index', [ |
162 | 167 | 'columns' => get_current_screen()->get_columns(), |
@@ -192,7 +197,8 @@ discard block |
||
192 | 197 | */ |
193 | 198 | protected function getPostTypesWithArchive() |
194 | 199 | { |
195 | - $types = array_map( function( $value ) { |
|
200 | + $types = array_map( function( $value ) |
|
201 | + { |
|
196 | 202 | return sprintf( 'edit.php?post_type=%s', $value ); |
197 | 203 | }, get_post_types( ['has_archive' => 1] )); |
198 | 204 | return array_merge( $types, ['post' => 'edit.php'] ); |
@@ -22,8 +22,10 @@ discard block |
||
22 | 22 | */ |
23 | 23 | protected function generateInstructions() |
24 | 24 | { |
25 | - $instructions = array_reduce( $this->getInstructions(), function( $html, $metabox ) { |
|
26 | - $fields = array_reduce( $metabox['fields'], function( $html, $field ) use( $metabox ) { |
|
25 | + $instructions = array_reduce( $this->getInstructions(), function( $html, $metabox ) |
|
26 | + { |
|
27 | + $fields = array_reduce( $metabox['fields'], function( $html, $field ) use( $metabox ) |
|
28 | + { |
|
27 | 29 | return $this->validate( $field['condition'] ) |
28 | 30 | ? $html . $this->filter( 'instruction', "PostMeta::get('{$field['slug']}');", $field, $metabox ) . PHP_EOL |
29 | 31 | : $html; |
@@ -41,7 +43,8 @@ discard block |
||
41 | 43 | */ |
42 | 44 | protected function getInstructions() |
43 | 45 | { |
44 | - return array_filter( $this->metaboxes, function( $metabox ) { |
|
46 | + return array_filter( $this->metaboxes, function( $metabox ) |
|
47 | + { |
|
45 | 48 | return $this->validate( $metabox['condition'] ) |
46 | 49 | && $this->hasPostType( $metabox ); |
47 | 50 | }); |
@@ -52,7 +55,9 @@ discard block |
||
52 | 55 | */ |
53 | 56 | protected function initInstructions() |
54 | 57 | { |
55 | - if( !$this->showInstructions() )return; |
|
58 | + if( !$this->showInstructions() ) { |
|
59 | + return; |
|
60 | + } |
|
56 | 61 | return [ |
57 | 62 | 'infodiv' => [ |
58 | 63 | 'context' => 'side', |
@@ -73,7 +78,8 @@ discard block |
||
73 | 78 | */ |
74 | 79 | protected function showInstructions() |
75 | 80 | { |
76 | - return $this->filter( 'show/instructions', count( array_filter( $this->metaboxes, function( $metabox ) { |
|
81 | + return $this->filter( 'show/instructions', count( array_filter( $this->metaboxes, function( $metabox ) |
|
82 | + { |
|
77 | 83 | return $this->show( false, $metabox ); |
78 | 84 | })) > 0 ); |
79 | 85 | } |
@@ -138,7 +138,9 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function register() |
140 | 140 | { |
141 | - if(( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
141 | + if(( new Helper )->getCurrentScreen()->id != $this->hook ) { |
|
142 | + return; |
|
143 | + } |
|
142 | 144 | foreach( parent::register() as $metabox ) { |
143 | 145 | new RWMetaBox( $metabox, static::ID, $this ); |
144 | 146 | } |
@@ -164,7 +166,9 @@ discard block |
||
164 | 166 | */ |
165 | 167 | public function renderFooterScript() |
166 | 168 | { |
167 | - if(( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
169 | + if(( new Helper )->getCurrentScreen()->id != $this->hook ) { |
|
170 | + return; |
|
171 | + } |
|
168 | 172 | $this->render( 'settings/script', [ |
169 | 173 | 'confirm' => __( 'Are you sure want to do this?', 'pollux' ), |
170 | 174 | 'hook' => $this->hook, |
@@ -212,7 +216,9 @@ discard block |
||
212 | 216 | { |
213 | 217 | if( filter_input( INPUT_GET, 'page' ) !== static::id() |
214 | 218 | || filter_input( INPUT_GET, 'action' ) !== 'reset' |
215 | - )return; |
|
219 | + ) { |
|
220 | + return; |
|
221 | + } |
|
216 | 222 | if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook )) { |
217 | 223 | update_option( static::id(), $this->getDefaults() ); |
218 | 224 | add_settings_error( static::id(), 'reset', __( 'Reset successful.', 'pollux' ), 'updated' ); |
@@ -231,7 +237,8 @@ discard block |
||
231 | 237 | */ |
232 | 238 | protected function filterArrayByKey( array $array, $key ) |
233 | 239 | { |
234 | - return array_filter( $array, function( $value ) use( $key ) { |
|
240 | + return array_filter( $array, function( $value ) use( $key ) |
|
241 | + { |
|
235 | 242 | return !empty( $value[$key] ); |
236 | 243 | }); |
237 | 244 | } |
@@ -243,8 +250,10 @@ discard block |
||
243 | 250 | { |
244 | 251 | $metaboxes = $this->filterArrayByKey( $this->metaboxes, 'slug' ); |
245 | 252 | |
246 | - array_walk( $metaboxes, function( &$metabox ) { |
|
247 | - $fields = array_map( function( $field ) { |
|
253 | + array_walk( $metaboxes, function( &$metabox ) |
|
254 | + { |
|
255 | + $fields = array_map( function( $field ) |
|
256 | + { |
|
248 | 257 | $field = wp_parse_args( $field, ['std' => ''] ); |
249 | 258 | return [$field['slug'] => $field['std']]; |
250 | 259 | }, $this->filterArrayByKey( $metabox['fields'], 'slug' )); |
@@ -197,7 +197,8 @@ discard block |
||
197 | 197 | */ |
198 | 198 | protected function normalizeFields( array $fields, array $data, $parentId ) |
199 | 199 | { |
200 | - return array_map( function( $id, $field ) use( $parentId ) { |
|
200 | + return array_map( function( $id, $field ) use( $parentId ) |
|
201 | + { |
|
201 | 202 | $defaults = [ |
202 | 203 | 'attributes' => [], |
203 | 204 | 'class' => '', |
@@ -236,7 +237,9 @@ discard block |
||
236 | 237 | protected function normalizeValidation( array $validation, array $data, $parentId ) |
237 | 238 | { |
238 | 239 | foreach( ['messages', 'rules'] as $key ) { |
239 | - if( empty( $validation[$key] ))continue; |
|
240 | + if( empty( $validation[$key] )) { |
|
241 | + continue; |
|
242 | + } |
|
240 | 243 | foreach( $validation[$key] as $id => $value ) { |
241 | 244 | $validation[$key][$this->normalizeFieldName( $id, ['slug' => $id], $parentId )] = $value; |
242 | 245 | unset( $validation[$key][$id] ); |
@@ -252,8 +255,11 @@ discard block |
||
252 | 255 | { |
253 | 256 | $fields = &$metabox['fields']; |
254 | 257 | $depends = array_column( $fields, 'depends' ); |
255 | - array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) { |
|
256 | - if( empty( $value ))return; |
|
258 | + array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) |
|
259 | + { |
|
260 | + if( empty( $value )) { |
|
261 | + return; |
|
262 | + } |
|
257 | 263 | $dependency = array_search( $value, array_column( $fields, 'id' )); |
258 | 264 | $fields[$index]['attributes']['data-depends'] = $value; |
259 | 265 | if( !$this->getMetaValue( $fields[$dependency]['slug'], '', $metabox['slug'] )) { |