@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | /** |
| 20 | 20 | * @var array |
| 21 | 21 | */ |
| 22 | - public $metaboxes = []; |
|
| 22 | + public $metaboxes = [ ]; |
|
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * {@inheritdoc} |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | $this->normalize(); |
| 30 | 30 | |
| 31 | - add_filter( 'rwmb_show', [$this, 'show'], 10, 2 ); |
|
| 32 | - add_filter( 'rwmb_meta_boxes', [$this, 'register'] ); |
|
| 31 | + add_filter( 'rwmb_show', [ $this, 'show' ], 10, 2 ); |
|
| 32 | + add_filter( 'rwmb_meta_boxes', [ $this, 'register' ] ); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -38,12 +38,12 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | public function register() |
| 40 | 40 | { |
| 41 | - if( current_user_can( 'switch_themes' )) { |
|
| 41 | + if( current_user_can( 'switch_themes' ) ) { |
|
| 42 | 42 | $this->addInstructions(); |
| 43 | 43 | } |
| 44 | 44 | $metaboxes = func_num_args() |
| 45 | - ? ( new Helper )->toArray( func_get_arg(0) ) |
|
| 46 | - : []; |
|
| 45 | + ? ( new Helper )->toArray( func_get_arg( 0 ) ) |
|
| 46 | + : [ ]; |
|
| 47 | 47 | return array_merge( $metaboxes, $this->metaboxes ); |
| 48 | 48 | } |
| 49 | 49 | |
@@ -54,11 +54,11 @@ discard block |
||
| 54 | 54 | public function show( $bool, array $metabox ) |
| 55 | 55 | { |
| 56 | 56 | if( defined( 'DOING_AJAX' ) |
| 57 | - || !isset( $metabox['condition'] ) |
|
| 58 | - || !$this->hasPostType( $metabox )) { |
|
| 57 | + || !isset( $metabox[ 'condition' ] ) |
|
| 58 | + || !$this->hasPostType( $metabox ) ) { |
|
| 59 | 59 | return $bool; |
| 60 | 60 | } |
| 61 | - return $this->validate( $metabox['condition'] ); |
|
| 61 | + return $this->validate( $metabox[ 'condition' ] ); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | protected function getPostId() |
| 68 | 68 | { |
| 69 | - if( !( $postId = filter_input( INPUT_GET, 'post' ))) { |
|
| 69 | + if( !( $postId = filter_input( INPUT_GET, 'post' ) ) ) { |
|
| 70 | 70 | $postId = filter_input( INPUT_POST, 'post_ID' ); |
| 71 | 71 | } |
| 72 | 72 | return intval( $postId ); |
@@ -79,10 +79,10 @@ discard block |
||
| 79 | 79 | { |
| 80 | 80 | return array_unique( iterator_to_array( |
| 81 | 81 | new RecursiveIteratorIterator( |
| 82 | - new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' )) |
|
| 82 | + new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' ) ) |
|
| 83 | 83 | ), |
| 84 | 84 | false |
| 85 | - )); |
|
| 85 | + ) ); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | { |
| 93 | 93 | return ( new PostMeta )->get( $key, [ |
| 94 | 94 | 'id' => $this->getPostId(), |
| 95 | - ]); |
|
| 95 | + ] ); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -100,10 +100,10 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | protected function hasPostType( array $metabox ) |
| 102 | 102 | { |
| 103 | - if( !isset( $metabox['post_types'] )) { |
|
| 103 | + if( !isset( $metabox[ 'post_types' ] ) ) { |
|
| 104 | 104 | return true; |
| 105 | 105 | } |
| 106 | - return in_array( get_post_type( $this->getPostId() ), $metabox['post_types'] ); |
|
| 106 | + return in_array( get_post_type( $this->getPostId() ), $metabox[ 'post_types' ] ); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -111,15 +111,15 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | protected function normalize() |
| 113 | 113 | { |
| 114 | - foreach( $this->app->config['meta_boxes'] as $id => $metabox ) { |
|
| 114 | + foreach( $this->app->config[ 'meta_boxes' ] as $id => $metabox ) { |
|
| 115 | 115 | $defaults = [ |
| 116 | - 'condition' => [], |
|
| 117 | - 'fields' => [], |
|
| 116 | + 'condition' => [ ], |
|
| 117 | + 'fields' => [ ], |
|
| 118 | 118 | 'id' => $id, |
| 119 | - 'post_types' => [], |
|
| 119 | + 'post_types' => [ ], |
|
| 120 | 120 | 'slug' => $id, |
| 121 | 121 | ]; |
| 122 | - $this->metaboxes[] = $this->setDependencies( |
|
| 122 | + $this->metaboxes[ ] = $this->setDependencies( |
|
| 123 | 123 | $this->normalizeThis( $metabox, $defaults, $id ) |
| 124 | 124 | ); |
| 125 | 125 | } |
@@ -143,8 +143,8 @@ discard block |
||
| 143 | 143 | protected function normalizeFields( array $fields, array $data, $parentId ) |
| 144 | 144 | { |
| 145 | 145 | return array_map( function( $id, $field ) use( $parentId ) { |
| 146 | - $defaults = [ |
|
| 147 | - 'attributes' => [], |
|
| 146 | + $defaults = [ |
|
| 147 | + 'attributes' => [ ], |
|
| 148 | 148 | 'class' => '', |
| 149 | 149 | // 'condition' => [], |
| 150 | 150 | 'depends' => '', |
@@ -180,14 +180,14 @@ discard block |
||
| 180 | 180 | */ |
| 181 | 181 | protected function setDependencies( array $metabox ) |
| 182 | 182 | { |
| 183 | - $fields = &$metabox['fields']; |
|
| 183 | + $fields = &$metabox[ 'fields' ]; |
|
| 184 | 184 | $depends = array_column( $fields, 'depends' ); |
| 185 | 185 | array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) { |
| 186 | - if( empty( $value ))return; |
|
| 187 | - $dependency = array_search( $value, array_column( $fields, 'id' )); |
|
| 188 | - $fields[$index]['attributes']['data-depends'] = $value; |
|
| 189 | - if( !$this->getValue( $fields[$dependency]['slug'], $metabox['slug'] )) { |
|
| 190 | - $fields[$index]['class'] = trim( 'hidden ' . $fields[$index]['class'] ); |
|
| 186 | + if( empty( $value ) )return; |
|
| 187 | + $dependency = array_search( $value, array_column( $fields, 'id' ) ); |
|
| 188 | + $fields[ $index ][ 'attributes' ][ 'data-depends' ] = $value; |
|
| 189 | + if( !$this->getValue( $fields[ $dependency ][ 'slug' ], $metabox[ 'slug' ] ) ) { |
|
| 190 | + $fields[ $index ][ 'class' ] = trim( 'hidden ' . $fields[ $index ][ 'class' ] ); |
|
| 191 | 191 | } |
| 192 | 192 | }); |
| 193 | 193 | return $metabox; |
@@ -142,7 +142,8 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | protected function normalizeFields( array $fields, array $data, $parentId ) |
| 144 | 144 | { |
| 145 | - return array_map( function( $id, $field ) use( $parentId ) { |
|
| 145 | + return array_map( function( $id, $field ) use( $parentId ) |
|
| 146 | + { |
|
| 146 | 147 | $defaults = [ |
| 147 | 148 | 'attributes' => [], |
| 148 | 149 | 'class' => '', |
@@ -182,8 +183,11 @@ discard block |
||
| 182 | 183 | { |
| 183 | 184 | $fields = &$metabox['fields']; |
| 184 | 185 | $depends = array_column( $fields, 'depends' ); |
| 185 | - array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) { |
|
| 186 | - if( empty( $value ))return; |
|
| 186 | + array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) |
|
| 187 | + { |
|
| 188 | + if( empty( $value )) { |
|
| 189 | + return; |
|
| 190 | + } |
|
| 187 | 191 | $dependency = array_search( $value, array_column( $fields, 'id' )); |
| 188 | 192 | $fields[$index]['attributes']['data-depends'] = $value; |
| 189 | 193 | if( !$this->getValue( $fields[$dependency]['slug'], $metabox['slug'] )) { |