@@ -19,20 +19,20 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * @var array |
21 | 21 | */ |
22 | - public $metaboxes = []; |
|
22 | + public $metaboxes = [ ]; |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * {@inheritdoc} |
26 | 26 | */ |
27 | 27 | public function init() |
28 | 28 | { |
29 | - $this->normalize( $this->app->config['meta_boxes'], [ |
|
30 | - 'post_types' => [], |
|
31 | - ]); |
|
29 | + $this->normalize( $this->app->config[ 'meta_boxes' ], [ |
|
30 | + 'post_types' => [ ], |
|
31 | + ] ); |
|
32 | 32 | |
33 | - add_filter( 'rwmb_show', [$this, 'show'], 10, 2 ); |
|
34 | - add_filter( 'rwmb_meta_boxes', [$this, 'register'] ); |
|
35 | - add_filter( 'rwmb_outer_html', [$this, 'renderField'], 10, 2 ); |
|
33 | + add_filter( 'rwmb_show', [ $this, 'show' ], 10, 2 ); |
|
34 | + add_filter( 'rwmb_meta_boxes', [ $this, 'register' ] ); |
|
35 | + add_filter( 'rwmb_outer_html', [ $this, 'renderField' ], 10, 2 ); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -41,12 +41,12 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function register() |
43 | 43 | { |
44 | - if( current_user_can( 'switch_themes' )) { |
|
44 | + if( current_user_can( 'switch_themes' ) ) { |
|
45 | 45 | $this->addInstructions(); |
46 | 46 | } |
47 | 47 | $metaboxes = func_num_args() |
48 | - ? ( new Helper )->toArray( func_get_arg(0) ) |
|
49 | - : []; |
|
48 | + ? ( new Helper )->toArray( func_get_arg( 0 ) ) |
|
49 | + : [ ]; |
|
50 | 50 | return array_merge( $metaboxes, $this->metaboxes ); |
51 | 51 | } |
52 | 52 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function renderField( $html, $field ) |
58 | 58 | { |
59 | - return $this->validate( $field['condition'] ) |
|
59 | + return $this->validate( $field[ 'condition' ] ) |
|
60 | 60 | ? $html |
61 | 61 | : ''; |
62 | 62 | } |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | public function show( $bool, array $metabox ) |
69 | 69 | { |
70 | 70 | if( defined( 'DOING_AJAX' ) |
71 | - || !isset( $metabox['condition'] ) |
|
72 | - || !$this->hasPostType( $metabox )) { |
|
71 | + || !isset( $metabox[ 'condition' ] ) |
|
72 | + || !$this->hasPostType( $metabox ) ) { |
|
73 | 73 | return $bool; |
74 | 74 | } |
75 | - return $this->validate( $metabox['condition'] ); |
|
75 | + return $this->validate( $metabox[ 'condition' ] ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | protected function getPostId() |
82 | 82 | { |
83 | - if( !( $postId = filter_input( INPUT_GET, 'post' ))) { |
|
83 | + if( !( $postId = filter_input( INPUT_GET, 'post' ) ) ) { |
|
84 | 84 | $postId = filter_input( INPUT_POST, 'post_ID' ); |
85 | 85 | } |
86 | 86 | return intval( $postId ); |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | { |
94 | 94 | return array_unique( iterator_to_array( |
95 | 95 | new RecursiveIteratorIterator( |
96 | - new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' )) |
|
96 | + new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' ) ) |
|
97 | 97 | ), |
98 | 98 | false |
99 | - )); |
|
99 | + ) ); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | { |
107 | 107 | return PostMeta::get( $key, [ |
108 | 108 | 'id' => $this->getPostId(), |
109 | - ]); |
|
109 | + ] ); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -114,25 +114,25 @@ discard block |
||
114 | 114 | */ |
115 | 115 | protected function hasPostType( array $metabox ) |
116 | 116 | { |
117 | - if( !isset( $metabox['post_types'] )) { |
|
117 | + if( !isset( $metabox[ 'post_types' ] ) ) { |
|
118 | 118 | return true; |
119 | 119 | } |
120 | - return in_array( get_post_type( $this->getPostId() ), $metabox['post_types'] ); |
|
120 | + return in_array( get_post_type( $this->getPostId() ), $metabox[ 'post_types' ] ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | 124 | * @return void |
125 | 125 | */ |
126 | - protected function normalize( array $metaboxes, array $defaults = [] ) |
|
126 | + protected function normalize( array $metaboxes, array $defaults = [ ] ) |
|
127 | 127 | { |
128 | 128 | foreach( $metaboxes as $id => $metabox ) { |
129 | 129 | $data = wp_parse_args( $defaults, [ |
130 | - 'condition' => [], |
|
131 | - 'fields' => [], |
|
130 | + 'condition' => [ ], |
|
131 | + 'fields' => [ ], |
|
132 | 132 | 'id' => $id, |
133 | 133 | 'slug' => $id, |
134 | - ]); |
|
135 | - $this->metaboxes[] = $this->setDependencies( |
|
134 | + ] ); |
|
135 | + $this->metaboxes[ ] = $this->setDependencies( |
|
136 | 136 | $this->normalizeThis( $metabox, $data, $id ) |
137 | 137 | ); |
138 | 138 | } |
@@ -166,10 +166,10 @@ discard block |
||
166 | 166 | protected function normalizeFields( array $fields, array $data, $parentId ) |
167 | 167 | { |
168 | 168 | return array_map( function( $id, $field ) use( $parentId ) { |
169 | - $defaults = [ |
|
170 | - 'attributes' => [], |
|
169 | + $defaults = [ |
|
170 | + 'attributes' => [ ], |
|
171 | 171 | 'class' => '', |
172 | - 'condition' => [], |
|
172 | + 'condition' => [ ], |
|
173 | 173 | 'depends' => '', |
174 | 174 | 'field_name' => $id, |
175 | 175 | 'id' => $id, |
@@ -203,14 +203,14 @@ discard block |
||
203 | 203 | */ |
204 | 204 | protected function setDependencies( array $metabox ) |
205 | 205 | { |
206 | - $fields = &$metabox['fields']; |
|
206 | + $fields = &$metabox[ 'fields' ]; |
|
207 | 207 | $depends = array_column( $fields, 'depends' ); |
208 | 208 | array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) { |
209 | - if( empty( $value ))return; |
|
210 | - $dependency = array_search( $value, array_column( $fields, 'id' )); |
|
211 | - $fields[$index]['attributes']['data-depends'] = $value; |
|
212 | - if( !$this->getValue( $fields[$dependency]['slug'], $metabox['slug'] )) { |
|
213 | - $fields[$index]['class'] = trim( 'hidden ' . $fields[$index]['class'] ); |
|
209 | + if( empty( $value ) )return; |
|
210 | + $dependency = array_search( $value, array_column( $fields, 'id' ) ); |
|
211 | + $fields[ $index ][ 'attributes' ][ 'data-depends' ] = $value; |
|
212 | + if( !$this->getValue( $fields[ $dependency ][ 'slug' ], $metabox[ 'slug' ] ) ) { |
|
213 | + $fields[ $index ][ 'class' ] = trim( 'hidden ' . $fields[ $index ][ 'class' ] ); |
|
214 | 214 | } |
215 | 215 | }); |
216 | 216 | return $metabox; |