@@ -86,6 +86,7 @@ |
||
86 | 86 | abstract public function filter( $name, ...$args ); |
87 | 87 | |
88 | 88 | /** |
89 | + * @param boolean $bool |
|
89 | 90 | * @return bool |
90 | 91 | * @filter rwmb_show |
91 | 92 | */ |
@@ -23,13 +23,13 @@ discard block |
||
23 | 23 | protected function generateInstructions() |
24 | 24 | { |
25 | 25 | $instructions = array_reduce( $this->getInstructions(), function( $html, $metabox ) { |
26 | - $fields = array_reduce( $metabox['fields'], function( $html, $field ) use( $metabox ) { |
|
27 | - return $this->validate( $field['condition'] ) |
|
28 | - ? $html . $this->filter( 'instruction', "PostMeta::get('{$field['slug']}');", $field, $metabox ) . PHP_EOL |
|
26 | + $fields = array_reduce( $metabox[ 'fields' ], function( $html, $field ) use( $metabox ) { |
|
27 | + return $this->validate( $field[ 'condition' ] ) |
|
28 | + ? $html . $this->filter( 'instruction', "PostMeta::get('{$field[ 'slug' ]}');", $field, $metabox ) . PHP_EOL |
|
29 | 29 | : $html; |
30 | 30 | }); |
31 | 31 | return $html . sprintf( '<p><strong>%s</strong></p><pre class="my-sites nav-tab-active misc-pub-section">%s</pre>', |
32 | - $metabox['title'], |
|
32 | + $metabox[ 'title' ], |
|
33 | 33 | $fields |
34 | 34 | ); |
35 | 35 | }); |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | protected function getInstructions() |
43 | 43 | { |
44 | 44 | return array_filter( $this->metaboxes, function( $metabox ) { |
45 | - return $this->validate( $metabox['condition'] ) |
|
45 | + return $this->validate( $metabox[ 'condition' ] ) |
|
46 | 46 | && $this->hasPostType( $metabox ); |
47 | 47 | }); |
48 | 48 | } |
@@ -56,11 +56,11 @@ discard block |
||
56 | 56 | return [ |
57 | 57 | 'infodiv' => [ |
58 | 58 | 'context' => 'side', |
59 | - 'fields' => [[ |
|
59 | + 'fields' => [ [ |
|
60 | 60 | 'slug' => '', |
61 | 61 | 'std' => $this->generateInstructions(), |
62 | 62 | 'type' => 'custom_html', |
63 | - ]], |
|
63 | + ] ], |
|
64 | 64 | 'post_types' => $this->getPostTypes(), |
65 | 65 | 'priority' => 'low', |
66 | 66 | 'title' => __( 'How to use in your theme', 'pollux' ), |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | { |
76 | 76 | return $this->filter( 'show/instructions', count( array_filter( $this->metaboxes, function( $metabox ) { |
77 | 77 | return $this->show( false, $metabox ); |
78 | - })) > 0 ); |
|
78 | + }) ) > 0 ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -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 | } |
@@ -24,20 +24,20 @@ discard block |
||
24 | 24 | /** |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - public $metaboxes = []; |
|
27 | + public $metaboxes = [ ]; |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * {@inheritdoc} |
31 | 31 | */ |
32 | 32 | public function init() |
33 | 33 | { |
34 | - $this->normalize( $this->app->config[static::ID], [ |
|
35 | - 'post_types' => [], |
|
36 | - ]); |
|
34 | + $this->normalize( $this->app->config[ static::ID ], [ |
|
35 | + 'post_types' => [ ], |
|
36 | + ] ); |
|
37 | 37 | |
38 | - add_filter( 'rwmb_show', [$this, 'show'], 10, 2 ); |
|
39 | - add_filter( 'rwmb_meta_boxes', [$this, 'register'] ); |
|
40 | - add_filter( 'rwmb_outer_html', [$this, 'renderField'], 10, 2 ); |
|
38 | + add_filter( 'rwmb_show', [ $this, 'show' ], 10, 2 ); |
|
39 | + add_filter( 'rwmb_meta_boxes', [ $this, 'register' ] ); |
|
40 | + add_filter( 'rwmb_outer_html', [ $this, 'renderField' ], 10, 2 ); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -66,15 +66,15 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function register() |
68 | 68 | { |
69 | - if( current_user_can( 'switch_themes' )) { |
|
69 | + if( current_user_can( 'switch_themes' ) ) { |
|
70 | 70 | $instructions = $this->initInstructions(); |
71 | - if( is_array( $instructions )) { |
|
71 | + if( is_array( $instructions ) ) { |
|
72 | 72 | $this->normalize( $instructions ); |
73 | 73 | } |
74 | 74 | } |
75 | 75 | $metaboxes = func_num_args() |
76 | - ? ( new Helper )->toArray( func_get_arg(0) ) |
|
77 | - : []; |
|
76 | + ? ( new Helper )->toArray( func_get_arg( 0 ) ) |
|
77 | + : [ ]; |
|
78 | 78 | return array_merge( $metaboxes, $this->metaboxes ); |
79 | 79 | } |
80 | 80 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function renderField( $html, $field ) |
86 | 86 | { |
87 | - return $this->validate( $field['condition'] ) |
|
87 | + return $this->validate( $field[ 'condition' ] ) |
|
88 | 88 | ? $html |
89 | 89 | : ''; |
90 | 90 | } |
@@ -96,11 +96,11 @@ discard block |
||
96 | 96 | public function show( $bool, array $metabox ) |
97 | 97 | { |
98 | 98 | if( defined( 'DOING_AJAX' ) |
99 | - || !isset( $metabox['condition'] ) |
|
100 | - || !$this->hasPostType( $metabox )) { |
|
99 | + || !isset( $metabox[ 'condition' ] ) |
|
100 | + || !$this->hasPostType( $metabox ) ) { |
|
101 | 101 | return $bool; |
102 | 102 | } |
103 | - return $this->validate( $metabox['condition'] ); |
|
103 | + return $this->validate( $metabox[ 'condition' ] ); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | protected function getPostId() |
110 | 110 | { |
111 | - if( !( $postId = filter_input( INPUT_GET, 'post' ))) { |
|
111 | + if( !( $postId = filter_input( INPUT_GET, 'post' ) ) ) { |
|
112 | 112 | $postId = filter_input( INPUT_POST, 'post_ID' ); |
113 | 113 | } |
114 | 114 | return intval( $postId ); |
@@ -121,10 +121,10 @@ discard block |
||
121 | 121 | { |
122 | 122 | return array_unique( iterator_to_array( |
123 | 123 | new RecursiveIteratorIterator( |
124 | - new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' )) |
|
124 | + new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' ) ) |
|
125 | 125 | ), |
126 | 126 | false |
127 | - )); |
|
127 | + ) ); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | { |
135 | 135 | return PostMeta::get( $key, [ |
136 | 136 | 'id' => $this->getPostId(), |
137 | - ]); |
|
137 | + ] ); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -142,26 +142,26 @@ discard block |
||
142 | 142 | */ |
143 | 143 | protected function hasPostType( array $metabox ) |
144 | 144 | { |
145 | - if( !isset( $metabox['post_types'] )) { |
|
145 | + if( !isset( $metabox[ 'post_types' ] ) ) { |
|
146 | 146 | return true; |
147 | 147 | } |
148 | - return in_array( get_post_type( $this->getPostId() ), $metabox['post_types'] ); |
|
148 | + return in_array( get_post_type( $this->getPostId() ), $metabox[ 'post_types' ] ); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
152 | 152 | * @return void |
153 | 153 | */ |
154 | - protected function normalize( array $metaboxes, array $defaults = [] ) |
|
154 | + protected function normalize( array $metaboxes, array $defaults = [ ] ) |
|
155 | 155 | { |
156 | 156 | foreach( $metaboxes as $id => $metabox ) { |
157 | 157 | $data = wp_parse_args( $defaults, [ |
158 | - 'condition' => [], |
|
159 | - 'fields' => [], |
|
158 | + 'condition' => [ ], |
|
159 | + 'fields' => [ ], |
|
160 | 160 | 'id' => $id, |
161 | 161 | 'slug' => $id, |
162 | - 'validation' => [], |
|
163 | - ]); |
|
164 | - $this->metaboxes[] = $this->setDependencies( |
|
162 | + 'validation' => [ ], |
|
163 | + ] ); |
|
164 | + $this->metaboxes[ ] = $this->setDependencies( |
|
165 | 165 | $this->normalizeThis( $metabox, $data, $id ) |
166 | 166 | ); |
167 | 167 | } |
@@ -195,10 +195,10 @@ discard block |
||
195 | 195 | protected function normalizeFields( array $fields, array $data, $parentId ) |
196 | 196 | { |
197 | 197 | return array_map( function( $id, $field ) use( $parentId ) { |
198 | - $defaults = [ |
|
199 | - 'attributes' => [], |
|
198 | + $defaults = [ |
|
199 | + 'attributes' => [ ], |
|
200 | 200 | 'class' => '', |
201 | - 'condition' => [], |
|
201 | + 'condition' => [ ], |
|
202 | 202 | 'depends' => '', |
203 | 203 | 'field_name' => $id, |
204 | 204 | 'id' => $id, |
@@ -232,11 +232,11 @@ discard block |
||
232 | 232 | */ |
233 | 233 | protected function normalizeValidation( array $validation, array $data, $parentId ) |
234 | 234 | { |
235 | - foreach( ['messages', 'rules'] as $key ) { |
|
236 | - if( empty( $validation[$key] ))continue; |
|
237 | - foreach( $validation[$key] as $id => $value ) { |
|
238 | - $validation[$key][$this->normalizeFieldName( $id, ['slug' => $id], $parentId )] = $value; |
|
239 | - unset( $validation[$key][$id] ); |
|
235 | + foreach( [ 'messages', 'rules' ] as $key ) { |
|
236 | + if( empty( $validation[ $key ] ) )continue; |
|
237 | + foreach( $validation[ $key ] as $id => $value ) { |
|
238 | + $validation[ $key ][ $this->normalizeFieldName( $id, [ 'slug' => $id ], $parentId ) ] = $value; |
|
239 | + unset( $validation[ $key ][ $id ] ); |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | return $validation; |
@@ -247,14 +247,14 @@ discard block |
||
247 | 247 | */ |
248 | 248 | protected function setDependencies( array $metabox ) |
249 | 249 | { |
250 | - $fields = &$metabox['fields']; |
|
250 | + $fields = &$metabox[ 'fields' ]; |
|
251 | 251 | $depends = array_column( $fields, 'depends' ); |
252 | 252 | array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) { |
253 | - if( empty( $value ))return; |
|
254 | - $dependency = array_search( $value, array_column( $fields, 'id' )); |
|
255 | - $fields[$index]['attributes']['data-depends'] = $value; |
|
256 | - if( !$this->getValue( $fields[$dependency]['slug'], $metabox['slug'] )) { |
|
257 | - $fields[$index]['class'] = trim( 'hidden ' . $fields[$index]['class'] ); |
|
253 | + if( empty( $value ) )return; |
|
254 | + $dependency = array_search( $value, array_column( $fields, 'id' ) ); |
|
255 | + $fields[ $index ][ 'attributes' ][ 'data-depends' ] = $value; |
|
256 | + if( !$this->getValue( $fields[ $dependency ][ 'slug' ], $metabox[ 'slug' ] ) ) { |
|
257 | + $fields[ $index ][ 'class' ] = trim( 'hidden ' . $fields[ $index ][ 'class' ] ); |
|
258 | 258 | } |
259 | 259 | }); |
260 | 260 | return $metabox; |