@@ -25,23 +25,23 @@ discard block |
||
| 25 | 25 | /** |
| 26 | 26 | * @var array |
| 27 | 27 | */ |
| 28 | - public $metaboxes = []; |
|
| 28 | + public $metaboxes = [ ]; |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * {@inheritdoc} |
| 32 | 32 | */ |
| 33 | 33 | public function init() |
| 34 | 34 | { |
| 35 | - if( empty( $this->app->config->{static::ID} ))return; |
|
| 35 | + if( empty( $this->app->config->{static::ID} ) )return; |
|
| 36 | 36 | |
| 37 | 37 | $this->normalize( $this->app->config->{static::ID}, [ |
| 38 | - 'post_types' => [], |
|
| 39 | - ]); |
|
| 38 | + 'post_types' => [ ], |
|
| 39 | + ] ); |
|
| 40 | 40 | |
| 41 | - add_filter( 'rwmb_normalize_map_field', [$this, 'normalizeMapField'] ); |
|
| 42 | - add_filter( 'rwmb_show', [$this, 'show'], 10, 2 ); |
|
| 43 | - add_filter( 'rwmb_meta_boxes', [$this, 'register'] ); |
|
| 44 | - add_filter( 'rwmb_outer_html', [$this, 'renderField'], 10, 2 ); |
|
| 41 | + add_filter( 'rwmb_normalize_map_field', [ $this, 'normalizeMapField' ] ); |
|
| 42 | + add_filter( 'rwmb_show', [ $this, 'show' ], 10, 2 ); |
|
| 43 | + add_filter( 'rwmb_meta_boxes', [ $this, 'register' ] ); |
|
| 44 | + add_filter( 'rwmb_outer_html', [ $this, 'renderField' ], 10, 2 ); |
|
| 45 | 45 | |
| 46 | 46 | } |
| 47 | 47 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | { |
| 76 | 76 | return PostMeta::get( $key, [ |
| 77 | 77 | 'id' => $this->getPostId(), |
| 78 | - ]); |
|
| 78 | + ] ); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -84,15 +84,15 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function normalizeMapField( $field ) |
| 86 | 86 | { |
| 87 | - if( empty( $field['address_field'] )) { |
|
| 87 | + if( empty( $field[ 'address_field' ] ) ) { |
|
| 88 | 88 | return $field; |
| 89 | 89 | } |
| 90 | - if( !$this->app->make( Helper::class )->startsWith( Application::PREFIX, $field['address_field'] )) { |
|
| 91 | - $field['address_field'] = Application::PREFIX . $field['address_field']; |
|
| 90 | + if( !$this->app->make( Helper::class )->startsWith( Application::PREFIX, $field[ 'address_field' ] ) ) { |
|
| 91 | + $field[ 'address_field' ] = Application::PREFIX . $field[ 'address_field' ]; |
|
| 92 | 92 | } |
| 93 | - $apiKey = SiteMeta::services( $field['api_key'] ); |
|
| 94 | - if( !empty( $apiKey ) && is_string( $apiKey )) { |
|
| 95 | - $field['api_key'] = $apiKey; |
|
| 93 | + $apiKey = SiteMeta::services( $field[ 'api_key' ] ); |
|
| 94 | + if( !empty( $apiKey ) && is_string( $apiKey ) ) { |
|
| 95 | + $field[ 'api_key' ] = $apiKey; |
|
| 96 | 96 | } |
| 97 | 97 | return $field; |
| 98 | 98 | } |
@@ -103,15 +103,15 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public function register() |
| 105 | 105 | { |
| 106 | - if( current_user_can( 'switch_themes' )) { |
|
| 106 | + if( current_user_can( 'switch_themes' ) ) { |
|
| 107 | 107 | $instructions = $this->initInstructions(); |
| 108 | - if( is_array( $instructions )) { |
|
| 108 | + if( is_array( $instructions ) ) { |
|
| 109 | 109 | $this->normalize( $instructions ); |
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | $metaboxes = func_num_args() |
| 113 | - ? ( new Helper )->toArray( func_get_arg(0) ) |
|
| 114 | - : []; |
|
| 113 | + ? ( new Helper )->toArray( func_get_arg( 0 ) ) |
|
| 114 | + : [ ]; |
|
| 115 | 115 | return array_merge( $metaboxes, $this->metaboxes ); |
| 116 | 116 | } |
| 117 | 117 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public function renderField( $html, $field ) |
| 123 | 123 | { |
| 124 | - return $this->validate( $field['condition'] ) |
|
| 124 | + return $this->validate( $field[ 'condition' ] ) |
|
| 125 | 125 | ? $html |
| 126 | 126 | : ''; |
| 127 | 127 | } |
@@ -133,11 +133,11 @@ discard block |
||
| 133 | 133 | public function show( $bool, array $metabox ) |
| 134 | 134 | { |
| 135 | 135 | if( defined( 'DOING_AJAX' ) |
| 136 | - || !isset( $metabox['condition'] ) |
|
| 137 | - || !$this->hasPostType( $metabox )) { |
|
| 136 | + || !isset( $metabox[ 'condition' ] ) |
|
| 137 | + || !$this->hasPostType( $metabox ) ) { |
|
| 138 | 138 | return $bool; |
| 139 | 139 | } |
| 140 | - return $this->validate( $metabox['condition'] ); |
|
| 140 | + return $this->validate( $metabox[ 'condition' ] ); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | protected function getPostId() |
| 147 | 147 | { |
| 148 | - if( !( $postId = filter_input( INPUT_GET, 'post' ))) { |
|
| 148 | + if( !( $postId = filter_input( INPUT_GET, 'post' ) ) ) { |
|
| 149 | 149 | $postId = filter_input( INPUT_POST, 'post_ID' ); |
| 150 | 150 | } |
| 151 | 151 | return intval( $postId ); |
@@ -158,10 +158,10 @@ discard block |
||
| 158 | 158 | { |
| 159 | 159 | return array_unique( iterator_to_array( |
| 160 | 160 | new RecursiveIteratorIterator( |
| 161 | - new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' )) |
|
| 161 | + new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' ) ) |
|
| 162 | 162 | ), |
| 163 | 163 | false |
| 164 | - )); |
|
| 164 | + ) ); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -169,29 +169,29 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | protected function hasPostType( array $metabox ) |
| 171 | 171 | { |
| 172 | - if( !isset( $metabox['post_types'] )) { |
|
| 172 | + if( !isset( $metabox[ 'post_types' ] ) ) { |
|
| 173 | 173 | return true; |
| 174 | 174 | } |
| 175 | - if( !( $type = filter_input( INPUT_GET, 'post_type' ))) { |
|
| 175 | + if( !( $type = filter_input( INPUT_GET, 'post_type' ) ) ) { |
|
| 176 | 176 | $type = get_post_type( $this->getPostId() ); |
| 177 | 177 | } |
| 178 | - return in_array( $type, $metabox['post_types'] ); |
|
| 178 | + return in_array( $type, $metabox[ 'post_types' ] ); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
| 182 | 182 | * @return void |
| 183 | 183 | */ |
| 184 | - protected function normalize( array $metaboxes, array $defaults = [] ) |
|
| 184 | + protected function normalize( array $metaboxes, array $defaults = [ ] ) |
|
| 185 | 185 | { |
| 186 | 186 | foreach( $metaboxes as $id => $metabox ) { |
| 187 | 187 | $data = wp_parse_args( $defaults, [ |
| 188 | - 'condition' => [], |
|
| 189 | - 'fields' => [], |
|
| 188 | + 'condition' => [ ], |
|
| 189 | + 'fields' => [ ], |
|
| 190 | 190 | 'id' => $id, |
| 191 | 191 | 'slug' => $id, |
| 192 | - 'validation' => [], |
|
| 193 | - ]); |
|
| 194 | - $this->metaboxes[] = $this->setDependencies( |
|
| 192 | + 'validation' => [ ], |
|
| 193 | + ] ); |
|
| 194 | + $this->metaboxes[ ] = $this->setDependencies( |
|
| 195 | 195 | $this->normalizeThis( $metabox, $data, $id ) |
| 196 | 196 | ); |
| 197 | 197 | } |
@@ -225,10 +225,10 @@ discard block |
||
| 225 | 225 | protected function normalizeFields( array $fields, array $data, $parentId ) |
| 226 | 226 | { |
| 227 | 227 | return array_map( function( $id, $field ) use( $parentId ) { |
| 228 | - $defaults = [ |
|
| 229 | - 'attributes' => [], |
|
| 228 | + $defaults = [ |
|
| 229 | + 'attributes' => [ ], |
|
| 230 | 230 | 'class' => '', |
| 231 | - 'condition' => [], |
|
| 231 | + 'condition' => [ ], |
|
| 232 | 232 | 'depends' => '', |
| 233 | 233 | 'field_name' => $id, |
| 234 | 234 | 'id' => $id, |
@@ -262,11 +262,11 @@ discard block |
||
| 262 | 262 | */ |
| 263 | 263 | protected function normalizeValidation( array $validation, array $data, $parentId ) |
| 264 | 264 | { |
| 265 | - foreach( ['messages', 'rules'] as $key ) { |
|
| 266 | - if( empty( $validation[$key] ))continue; |
|
| 267 | - foreach( $validation[$key] as $id => $value ) { |
|
| 268 | - $validation[$key][$this->normalizeFieldName( $id, ['slug' => $id], $parentId )] = $value; |
|
| 269 | - unset( $validation[$key][$id] ); |
|
| 265 | + foreach( [ 'messages', 'rules' ] as $key ) { |
|
| 266 | + if( empty( $validation[ $key ] ) )continue; |
|
| 267 | + foreach( $validation[ $key ] as $id => $value ) { |
|
| 268 | + $validation[ $key ][ $this->normalizeFieldName( $id, [ 'slug' => $id ], $parentId ) ] = $value; |
|
| 269 | + unset( $validation[ $key ][ $id ] ); |
|
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | 272 | return $validation; |
@@ -277,14 +277,14 @@ discard block |
||
| 277 | 277 | */ |
| 278 | 278 | protected function setDependencies( array $metabox ) |
| 279 | 279 | { |
| 280 | - $fields = &$metabox['fields']; |
|
| 280 | + $fields = &$metabox[ 'fields' ]; |
|
| 281 | 281 | $depends = array_column( $fields, 'depends' ); |
| 282 | 282 | array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) { |
| 283 | - if( empty( $value ))return; |
|
| 284 | - $dependency = array_search( $value, array_column( $fields, 'id' )); |
|
| 285 | - $fields[$index]['attributes']['data-depends'] = $value; |
|
| 286 | - if( !$this->getMetaValue( $fields[$dependency]['slug'], '', $metabox['slug'] )) { |
|
| 287 | - $fields[$index]['class'] = trim( 'hidden ' . $fields[$index]['class'] ); |
|
| 283 | + if( empty( $value ) )return; |
|
| 284 | + $dependency = array_search( $value, array_column( $fields, 'id' ) ); |
|
| 285 | + $fields[ $index ][ 'attributes' ][ 'data-depends' ] = $value; |
|
| 286 | + if( !$this->getMetaValue( $fields[ $dependency ][ 'slug' ], '', $metabox[ 'slug' ] ) ) { |
|
| 287 | + $fields[ $index ][ 'class' ] = trim( 'hidden ' . $fields[ $index ][ 'class' ] ); |
|
| 288 | 288 | } |
| 289 | 289 | }); |
| 290 | 290 | return $metabox; |