@@ -181,7 +181,8 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | protected function normalizeFields( array $fields, array $data, $parentId ) |
| 183 | 183 | { |
| 184 | - return array_map( function( $id, $field ) use( $parentId ) { |
|
| 184 | + return array_map( function( $id, $field ) use( $parentId ) |
|
| 185 | + { |
|
| 185 | 186 | $defaults = [ |
| 186 | 187 | 'attributes' => [], |
| 187 | 188 | 'class' => '', |
@@ -220,7 +221,9 @@ discard block |
||
| 220 | 221 | protected function normalizeValidation( array $validation, array $data, $parentId ) |
| 221 | 222 | { |
| 222 | 223 | foreach( ['messages', 'rules'] as $key ) { |
| 223 | - if( empty( $validation[$key] ))continue; |
|
| 224 | + if( empty( $validation[$key] )) { |
|
| 225 | + continue; |
|
| 226 | + } |
|
| 224 | 227 | foreach( $validation[$key] as $id => $value ) { |
| 225 | 228 | $validation[$key][$this->normalizeFieldName( $id, ['slug' => $id], $parentId )] = $value; |
| 226 | 229 | unset( $validation[$key][$id] ); |
@@ -236,8 +239,11 @@ discard block |
||
| 236 | 239 | { |
| 237 | 240 | $fields = &$metabox['fields']; |
| 238 | 241 | $depends = array_column( $fields, 'depends' ); |
| 239 | - array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) { |
|
| 240 | - if( empty( $value ))return; |
|
| 242 | + array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) |
|
| 243 | + { |
|
| 244 | + if( empty( $value )) { |
|
| 245 | + return; |
|
| 246 | + } |
|
| 241 | 247 | $dependency = array_search( $value, array_column( $fields, 'id' )); |
| 242 | 248 | $fields[$index]['attributes']['data-depends'] = $value; |
| 243 | 249 | if( !$this->getValue( $fields[$dependency]['slug'], $metabox['slug'] )) { |
@@ -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,12 +66,12 @@ 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 | $this->addInstructions(); |
| 71 | 71 | } |
| 72 | 72 | $metaboxes = func_num_args() |
| 73 | - ? ( new Helper )->toArray( func_get_arg(0) ) |
|
| 74 | - : []; |
|
| 73 | + ? ( new Helper )->toArray( func_get_arg( 0 ) ) |
|
| 74 | + : [ ]; |
|
| 75 | 75 | return array_merge( $metaboxes, $this->metaboxes ); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public function renderField( $html, $field ) |
| 83 | 83 | { |
| 84 | - return $this->validate( $field['condition'] ) |
|
| 84 | + return $this->validate( $field[ 'condition' ] ) |
|
| 85 | 85 | ? $html |
| 86 | 86 | : ''; |
| 87 | 87 | } |
@@ -93,11 +93,11 @@ discard block |
||
| 93 | 93 | public function show( $bool, array $metabox ) |
| 94 | 94 | { |
| 95 | 95 | if( defined( 'DOING_AJAX' ) |
| 96 | - || !isset( $metabox['condition'] ) |
|
| 97 | - || !$this->hasPostType( $metabox )) { |
|
| 96 | + || !isset( $metabox[ 'condition' ] ) |
|
| 97 | + || !$this->hasPostType( $metabox ) ) { |
|
| 98 | 98 | return $bool; |
| 99 | 99 | } |
| 100 | - return $this->validate( $metabox['condition'] ); |
|
| 100 | + return $this->validate( $metabox[ 'condition' ] ); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | protected function getPostId() |
| 107 | 107 | { |
| 108 | - if( !( $postId = filter_input( INPUT_GET, 'post' ))) { |
|
| 108 | + if( !( $postId = filter_input( INPUT_GET, 'post' ) ) ) { |
|
| 109 | 109 | $postId = filter_input( INPUT_POST, 'post_ID' ); |
| 110 | 110 | } |
| 111 | 111 | return intval( $postId ); |
@@ -118,10 +118,10 @@ discard block |
||
| 118 | 118 | { |
| 119 | 119 | return array_unique( iterator_to_array( |
| 120 | 120 | new RecursiveIteratorIterator( |
| 121 | - new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' )) |
|
| 121 | + new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' ) ) |
|
| 122 | 122 | ), |
| 123 | 123 | false |
| 124 | - )); |
|
| 124 | + ) ); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | { |
| 132 | 132 | return PostMeta::get( $key, [ |
| 133 | 133 | 'id' => $this->getPostId(), |
| 134 | - ]); |
|
| 134 | + ] ); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -139,26 +139,26 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | protected function hasPostType( array $metabox ) |
| 141 | 141 | { |
| 142 | - if( !isset( $metabox['post_types'] )) { |
|
| 142 | + if( !isset( $metabox[ 'post_types' ] ) ) { |
|
| 143 | 143 | return true; |
| 144 | 144 | } |
| 145 | - return in_array( get_post_type( $this->getPostId() ), $metabox['post_types'] ); |
|
| 145 | + return in_array( get_post_type( $this->getPostId() ), $metabox[ 'post_types' ] ); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
| 149 | 149 | * @return void |
| 150 | 150 | */ |
| 151 | - protected function normalize( array $metaboxes, array $defaults = [] ) |
|
| 151 | + protected function normalize( array $metaboxes, array $defaults = [ ] ) |
|
| 152 | 152 | { |
| 153 | 153 | foreach( $metaboxes as $id => $metabox ) { |
| 154 | 154 | $data = wp_parse_args( $defaults, [ |
| 155 | - 'condition' => [], |
|
| 156 | - 'fields' => [], |
|
| 155 | + 'condition' => [ ], |
|
| 156 | + 'fields' => [ ], |
|
| 157 | 157 | 'id' => $id, |
| 158 | 158 | 'slug' => $id, |
| 159 | - 'validation' => [], |
|
| 160 | - ]); |
|
| 161 | - $this->metaboxes[] = $this->setDependencies( |
|
| 159 | + 'validation' => [ ], |
|
| 160 | + ] ); |
|
| 161 | + $this->metaboxes[ ] = $this->setDependencies( |
|
| 162 | 162 | $this->normalizeThis( $metabox, $data, $id ) |
| 163 | 163 | ); |
| 164 | 164 | } |
@@ -192,10 +192,10 @@ discard block |
||
| 192 | 192 | protected function normalizeFields( array $fields, array $data, $parentId ) |
| 193 | 193 | { |
| 194 | 194 | return array_map( function( $id, $field ) use( $parentId ) { |
| 195 | - $defaults = [ |
|
| 196 | - 'attributes' => [], |
|
| 195 | + $defaults = [ |
|
| 196 | + 'attributes' => [ ], |
|
| 197 | 197 | 'class' => '', |
| 198 | - 'condition' => [], |
|
| 198 | + 'condition' => [ ], |
|
| 199 | 199 | 'depends' => '', |
| 200 | 200 | 'field_name' => $id, |
| 201 | 201 | 'id' => $id, |
@@ -229,11 +229,11 @@ discard block |
||
| 229 | 229 | */ |
| 230 | 230 | protected function normalizeValidation( array $validation, array $data, $parentId ) |
| 231 | 231 | { |
| 232 | - foreach( ['messages', 'rules'] as $key ) { |
|
| 233 | - if( empty( $validation[$key] ))continue; |
|
| 234 | - foreach( $validation[$key] as $id => $value ) { |
|
| 235 | - $validation[$key][$this->normalizeFieldName( $id, ['slug' => $id], $parentId )] = $value; |
|
| 236 | - unset( $validation[$key][$id] ); |
|
| 232 | + foreach( [ 'messages', 'rules' ] as $key ) { |
|
| 233 | + if( empty( $validation[ $key ] ) )continue; |
|
| 234 | + foreach( $validation[ $key ] as $id => $value ) { |
|
| 235 | + $validation[ $key ][ $this->normalizeFieldName( $id, [ 'slug' => $id ], $parentId ) ] = $value; |
|
| 236 | + unset( $validation[ $key ][ $id ] ); |
|
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | return $validation; |
@@ -244,14 +244,14 @@ discard block |
||
| 244 | 244 | */ |
| 245 | 245 | protected function setDependencies( array $metabox ) |
| 246 | 246 | { |
| 247 | - $fields = &$metabox['fields']; |
|
| 247 | + $fields = &$metabox[ 'fields' ]; |
|
| 248 | 248 | $depends = array_column( $fields, 'depends' ); |
| 249 | 249 | array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) { |
| 250 | - if( empty( $value ))return; |
|
| 251 | - $dependency = array_search( $value, array_column( $fields, 'id' )); |
|
| 252 | - $fields[$index]['attributes']['data-depends'] = $value; |
|
| 253 | - if( !$this->getValue( $fields[$dependency]['slug'], $metabox['slug'] )) { |
|
| 254 | - $fields[$index]['class'] = trim( 'hidden ' . $fields[$index]['class'] ); |
|
| 250 | + if( empty( $value ) )return; |
|
| 251 | + $dependency = array_search( $value, array_column( $fields, 'id' ) ); |
|
| 252 | + $fields[ $index ][ 'attributes' ][ 'data-depends' ] = $value; |
|
| 253 | + if( !$this->getValue( $fields[ $dependency ][ 'slug' ], $metabox[ 'slug' ] ) ) { |
|
| 254 | + $fields[ $index ][ 'class' ] = trim( 'hidden ' . $fields[ $index ][ 'class' ] ); |
|
| 255 | 255 | } |
| 256 | 256 | }); |
| 257 | 257 | return $metabox; |
@@ -23,19 +23,19 @@ discard block |
||
| 23 | 23 | protected function addInstructions() |
| 24 | 24 | { |
| 25 | 25 | if( !$this->showInstructions() )return; |
| 26 | - $this->normalize([ |
|
| 26 | + $this->normalize( [ |
|
| 27 | 27 | 'infodiv' => [ |
| 28 | 28 | 'context' => 'side', |
| 29 | - 'fields' => [[ |
|
| 29 | + 'fields' => [ [ |
|
| 30 | 30 | 'slug' => '', |
| 31 | 31 | 'std' => $this->generateInstructions(), |
| 32 | 32 | 'type' => 'custom_html', |
| 33 | - ]], |
|
| 33 | + ] ], |
|
| 34 | 34 | 'post_types' => $this->getPostTypes(), |
| 35 | 35 | 'priority' => 'low', |
| 36 | 36 | 'title' => __( 'How to use in your theme', 'pollux' ), |
| 37 | 37 | ], |
| 38 | - ]); |
|
| 38 | + ] ); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | protected function generateInstructions() |
| 45 | 45 | { |
| 46 | 46 | $instructions = array_reduce( $this->getInstructions(), function( $html, $metabox ) { |
| 47 | - $fields = array_reduce( $metabox['fields'], function( $html, $field ) use( $metabox ) { |
|
| 48 | - return $this->validate( $field['condition'] ) |
|
| 49 | - ? $html . $this->filter( 'instruction', "PostMeta::get('{$field['slug']}');", $field, $metabox ) . PHP_EOL |
|
| 47 | + $fields = array_reduce( $metabox[ 'fields' ], function( $html, $field ) use( $metabox ) { |
|
| 48 | + return $this->validate( $field[ 'condition' ] ) |
|
| 49 | + ? $html . $this->filter( 'instruction', "PostMeta::get('{$field[ 'slug' ]}');", $field, $metabox ) . PHP_EOL |
|
| 50 | 50 | : $html; |
| 51 | 51 | }); |
| 52 | 52 | return $html . sprintf( '<p><strong>%s</strong></p><pre class="my-sites nav-tab-active misc-pub-section">%s</pre>', |
| 53 | - $metabox['title'], |
|
| 53 | + $metabox[ 'title' ], |
|
| 54 | 54 | $fields |
| 55 | 55 | ); |
| 56 | 56 | }); |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | protected function getInstructions() |
| 64 | 64 | { |
| 65 | 65 | return array_filter( $this->metaboxes, function( $metabox ) { |
| 66 | - return $this->validate( $metabox['condition'] ) |
|
| 66 | + return $this->validate( $metabox[ 'condition' ] ) |
|
| 67 | 67 | && $this->hasPostType( $metabox ); |
| 68 | 68 | }); |
| 69 | 69 | } |
@@ -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 | /** |
@@ -107,5 +107,5 @@ discard block |
||
| 107 | 107 | /** |
| 108 | 108 | * @return void |
| 109 | 109 | */ |
| 110 | - abstract protected function normalize( array $metaboxes, array $defaults = [] ); |
|
| 110 | + abstract protected function normalize( array $metaboxes, array $defaults = [ ] ); |
|
| 111 | 111 | } |
@@ -22,7 +22,9 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | protected function addInstructions() |
| 24 | 24 | { |
| 25 | - if( !$this->showInstructions() )return; |
|
| 25 | + if( !$this->showInstructions() ) { |
|
| 26 | + return; |
|
| 27 | + } |
|
| 26 | 28 | $this->normalize([ |
| 27 | 29 | 'infodiv' => [ |
| 28 | 30 | 'context' => 'side', |
@@ -43,8 +45,10 @@ discard block |
||
| 43 | 45 | */ |
| 44 | 46 | protected function generateInstructions() |
| 45 | 47 | { |
| 46 | - $instructions = array_reduce( $this->getInstructions(), function( $html, $metabox ) { |
|
| 47 | - $fields = array_reduce( $metabox['fields'], function( $html, $field ) use( $metabox ) { |
|
| 48 | + $instructions = array_reduce( $this->getInstructions(), function( $html, $metabox ) |
|
| 49 | + { |
|
| 50 | + $fields = array_reduce( $metabox['fields'], function( $html, $field ) use( $metabox ) |
|
| 51 | + { |
|
| 48 | 52 | return $this->validate( $field['condition'] ) |
| 49 | 53 | ? $html . $this->filter( 'instruction', "PostMeta::get('{$field['slug']}');", $field, $metabox ) . PHP_EOL |
| 50 | 54 | : $html; |
@@ -62,7 +66,8 @@ discard block |
||
| 62 | 66 | */ |
| 63 | 67 | protected function getInstructions() |
| 64 | 68 | { |
| 65 | - return array_filter( $this->metaboxes, function( $metabox ) { |
|
| 69 | + return array_filter( $this->metaboxes, function( $metabox ) |
|
| 70 | + { |
|
| 66 | 71 | return $this->validate( $metabox['condition'] ) |
| 67 | 72 | && $this->hasPostType( $metabox ); |
| 68 | 73 | }); |
@@ -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 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | public function __construct() |
| 19 | 19 | { |
| 20 | - $this->options = get_option( Settings::id(), [] ); |
|
| 20 | + $this->options = get_option( Settings::id(), [ ] ); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | $args = array_pad( $args, 2, null ); |
| 30 | 30 | $group = $this->$group; |
| 31 | - if( is_object( $group )) { |
|
| 31 | + if( is_object( $group ) ) { |
|
| 32 | 32 | return $group; |
| 33 | 33 | } |
| 34 | - return $this->get( $group, $args[0], $args[1] ); |
|
| 34 | + return $this->get( $group, $args[ 0 ], $args[ 1 ] ); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -43,11 +43,11 @@ discard block |
||
| 43 | 43 | if( $group == 'all' ) { |
| 44 | 44 | return (object) $this->options; |
| 45 | 45 | } |
| 46 | - if( empty( $group )) { |
|
| 46 | + if( empty( $group ) ) { |
|
| 47 | 47 | $group = $this->getDefaultGroup(); |
| 48 | 48 | } |
| 49 | - return isset( $this->options[$group] ) |
|
| 50 | - ? $this->options[$group] |
|
| 49 | + return isset( $this->options[ $group ] ) |
|
| 50 | + ? $this->options[ $group ] |
|
| 51 | 51 | : null; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -62,13 +62,13 @@ discard block |
||
| 62 | 62 | if( func_num_args() < 1 ) { |
| 63 | 63 | return $this->all; |
| 64 | 64 | } |
| 65 | - if( is_string( $group )) { |
|
| 65 | + if( is_string( $group ) ) { |
|
| 66 | 66 | $group = $this->$group; |
| 67 | 67 | } |
| 68 | - if( !is_array( $group )) { |
|
| 68 | + if( !is_array( $group ) ) { |
|
| 69 | 69 | return $fallback; |
| 70 | 70 | } |
| 71 | - if( is_null( $key )) { |
|
| 71 | + if( is_null( $key ) ) { |
|
| 72 | 72 | return $group; |
| 73 | 73 | } |
| 74 | 74 | return $this->getValue( $group, $key, $fallback ); |
@@ -89,11 +89,11 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | protected function getValue( array $group, $key, $fallback ) |
| 91 | 91 | { |
| 92 | - if( !array_key_exists( $key, $group )) { |
|
| 92 | + if( !array_key_exists( $key, $group ) ) { |
|
| 93 | 93 | return $fallback; |
| 94 | 94 | } |
| 95 | - return empty( $group[$key] ) && !is_null( $fallback ) |
|
| 95 | + return empty( $group[ $key ] ) && !is_null( $fallback ) |
|
| 96 | 96 | ? $fallback |
| 97 | - : $group[$key]; |
|
| 97 | + : $group[ $key ]; |
|
| 98 | 98 | } |
| 99 | 99 | } |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | { |
| 17 | 17 | public function __construct() |
| 18 | 18 | { |
| 19 | - $this->options = get_option( Archive::id(), [] ); |
|
| 19 | + $this->options = get_option( Archive::id(), [ ] ); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -4,7 +4,7 @@ |
||
| 4 | 4 | <a href="<?= $thickbox_url; ?>" id="set-post-thumbnail" class="thickbox"><?= $thumbnail; ?></a> |
| 5 | 5 | </p> |
| 6 | 6 | |
| 7 | -<?php if( get_post( $image_id )) : ?> |
|
| 7 | +<?php if( get_post( $image_id ) ) : ?> |
|
| 8 | 8 | |
| 9 | 9 | <p class="hide-if-no-js howto" id="set-post-thumbnail-desc"><?= $edit_image; ?></p> |
| 10 | 10 | <p class="hide-if-no-js"> |