@@ -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 | } |
@@ -62,7 +62,7 @@ |
||
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * @param string $key |
| 65 | - * @param mixed $fallback |
|
| 65 | + * @param string $fallback |
|
| 66 | 66 | * @param string $group |
| 67 | 67 | * @return string|array |
| 68 | 68 | */ |
@@ -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 | /** |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | { |
| 71 | 71 | return PostMeta::get( $key, [ |
| 72 | 72 | 'id' => $this->getPostId(), |
| 73 | - ]); |
|
| 73 | + ] ); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -79,15 +79,15 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | public function register() |
| 81 | 81 | { |
| 82 | - if( current_user_can( 'switch_themes' )) { |
|
| 82 | + if( current_user_can( 'switch_themes' ) ) { |
|
| 83 | 83 | $instructions = $this->initInstructions(); |
| 84 | - if( is_array( $instructions )) { |
|
| 84 | + if( is_array( $instructions ) ) { |
|
| 85 | 85 | $this->normalize( $instructions ); |
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | $metaboxes = func_num_args() |
| 89 | - ? ( new Helper )->toArray( func_get_arg(0) ) |
|
| 90 | - : []; |
|
| 89 | + ? ( new Helper )->toArray( func_get_arg( 0 ) ) |
|
| 90 | + : [ ]; |
|
| 91 | 91 | return array_merge( $metaboxes, $this->metaboxes ); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | public function renderField( $html, $field ) |
| 99 | 99 | { |
| 100 | - return $this->validate( $field['condition'] ) |
|
| 100 | + return $this->validate( $field[ 'condition' ] ) |
|
| 101 | 101 | ? $html |
| 102 | 102 | : ''; |
| 103 | 103 | } |
@@ -109,11 +109,11 @@ discard block |
||
| 109 | 109 | public function show( $bool, array $metabox ) |
| 110 | 110 | { |
| 111 | 111 | if( defined( 'DOING_AJAX' ) |
| 112 | - || !isset( $metabox['condition'] ) |
|
| 113 | - || !$this->hasPostType( $metabox )) { |
|
| 112 | + || !isset( $metabox[ 'condition' ] ) |
|
| 113 | + || !$this->hasPostType( $metabox ) ) { |
|
| 114 | 114 | return $bool; |
| 115 | 115 | } |
| 116 | - return $this->validate( $metabox['condition'] ); |
|
| 116 | + return $this->validate( $metabox[ 'condition' ] ); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | protected function getPostId() |
| 123 | 123 | { |
| 124 | - if( !( $postId = filter_input( INPUT_GET, 'post' ))) { |
|
| 124 | + if( !( $postId = filter_input( INPUT_GET, 'post' ) ) ) { |
|
| 125 | 125 | $postId = filter_input( INPUT_POST, 'post_ID' ); |
| 126 | 126 | } |
| 127 | 127 | return intval( $postId ); |
@@ -134,10 +134,10 @@ discard block |
||
| 134 | 134 | { |
| 135 | 135 | return array_unique( iterator_to_array( |
| 136 | 136 | new RecursiveIteratorIterator( |
| 137 | - new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' )) |
|
| 137 | + new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' ) ) |
|
| 138 | 138 | ), |
| 139 | 139 | false |
| 140 | - )); |
|
| 140 | + ) ); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -145,26 +145,26 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | protected function hasPostType( array $metabox ) |
| 147 | 147 | { |
| 148 | - if( !isset( $metabox['post_types'] )) { |
|
| 148 | + if( !isset( $metabox[ 'post_types' ] ) ) { |
|
| 149 | 149 | return true; |
| 150 | 150 | } |
| 151 | - return in_array( get_post_type( $this->getPostId() ), $metabox['post_types'] ); |
|
| 151 | + return in_array( get_post_type( $this->getPostId() ), $metabox[ 'post_types' ] ); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
| 155 | 155 | * @return void |
| 156 | 156 | */ |
| 157 | - protected function normalize( array $metaboxes, array $defaults = [] ) |
|
| 157 | + protected function normalize( array $metaboxes, array $defaults = [ ] ) |
|
| 158 | 158 | { |
| 159 | 159 | foreach( $metaboxes as $id => $metabox ) { |
| 160 | 160 | $data = wp_parse_args( $defaults, [ |
| 161 | - 'condition' => [], |
|
| 162 | - 'fields' => [], |
|
| 161 | + 'condition' => [ ], |
|
| 162 | + 'fields' => [ ], |
|
| 163 | 163 | 'id' => $id, |
| 164 | 164 | 'slug' => $id, |
| 165 | - 'validation' => [], |
|
| 166 | - ]); |
|
| 167 | - $this->metaboxes[] = $this->setDependencies( |
|
| 165 | + 'validation' => [ ], |
|
| 166 | + ] ); |
|
| 167 | + $this->metaboxes[ ] = $this->setDependencies( |
|
| 168 | 168 | $this->normalizeThis( $metabox, $data, $id ) |
| 169 | 169 | ); |
| 170 | 170 | } |
@@ -198,10 +198,10 @@ discard block |
||
| 198 | 198 | protected function normalizeFields( array $fields, array $data, $parentId ) |
| 199 | 199 | { |
| 200 | 200 | return array_map( function( $id, $field ) use( $parentId ) { |
| 201 | - $defaults = [ |
|
| 202 | - 'attributes' => [], |
|
| 201 | + $defaults = [ |
|
| 202 | + 'attributes' => [ ], |
|
| 203 | 203 | 'class' => '', |
| 204 | - 'condition' => [], |
|
| 204 | + 'condition' => [ ], |
|
| 205 | 205 | 'depends' => '', |
| 206 | 206 | 'field_name' => $id, |
| 207 | 207 | 'id' => $id, |
@@ -235,11 +235,11 @@ discard block |
||
| 235 | 235 | */ |
| 236 | 236 | protected function normalizeValidation( array $validation, array $data, $parentId ) |
| 237 | 237 | { |
| 238 | - foreach( ['messages', 'rules'] as $key ) { |
|
| 239 | - if( empty( $validation[$key] ))continue; |
|
| 240 | - foreach( $validation[$key] as $id => $value ) { |
|
| 241 | - $validation[$key][$this->normalizeFieldName( $id, ['slug' => $id], $parentId )] = $value; |
|
| 242 | - unset( $validation[$key][$id] ); |
|
| 238 | + foreach( [ 'messages', 'rules' ] as $key ) { |
|
| 239 | + if( empty( $validation[ $key ] ) )continue; |
|
| 240 | + foreach( $validation[ $key ] as $id => $value ) { |
|
| 241 | + $validation[ $key ][ $this->normalizeFieldName( $id, [ 'slug' => $id ], $parentId ) ] = $value; |
|
| 242 | + unset( $validation[ $key ][ $id ] ); |
|
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | return $validation; |
@@ -250,14 +250,14 @@ discard block |
||
| 250 | 250 | */ |
| 251 | 251 | protected function setDependencies( array $metabox ) |
| 252 | 252 | { |
| 253 | - $fields = &$metabox['fields']; |
|
| 253 | + $fields = &$metabox[ 'fields' ]; |
|
| 254 | 254 | $depends = array_column( $fields, 'depends' ); |
| 255 | 255 | array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) { |
| 256 | - if( empty( $value ))return; |
|
| 257 | - $dependency = array_search( $value, array_column( $fields, 'id' )); |
|
| 258 | - $fields[$index]['attributes']['data-depends'] = $value; |
|
| 259 | - if( !$this->getMetaValue( $fields[$dependency]['slug'], '', $metabox['slug'] )) { |
|
| 260 | - $fields[$index]['class'] = trim( 'hidden ' . $fields[$index]['class'] ); |
|
| 256 | + if( empty( $value ) )return; |
|
| 257 | + $dependency = array_search( $value, array_column( $fields, 'id' ) ); |
|
| 258 | + $fields[ $index ][ 'attributes' ][ 'data-depends' ] = $value; |
|
| 259 | + if( !$this->getMetaValue( $fields[ $dependency ][ 'slug' ], '', $metabox[ 'slug' ] ) ) { |
|
| 260 | + $fields[ $index ][ 'class' ] = trim( 'hidden ' . $fields[ $index ][ 'class' ] ); |
|
| 261 | 261 | } |
| 262 | 262 | }); |
| 263 | 263 | return $metabox; |
@@ -197,7 +197,8 @@ discard block |
||
| 197 | 197 | */ |
| 198 | 198 | protected function normalizeFields( array $fields, array $data, $parentId ) |
| 199 | 199 | { |
| 200 | - return array_map( function( $id, $field ) use( $parentId ) { |
|
| 200 | + return array_map( function( $id, $field ) use( $parentId ) |
|
| 201 | + { |
|
| 201 | 202 | $defaults = [ |
| 202 | 203 | 'attributes' => [], |
| 203 | 204 | 'class' => '', |
@@ -236,7 +237,9 @@ discard block |
||
| 236 | 237 | protected function normalizeValidation( array $validation, array $data, $parentId ) |
| 237 | 238 | { |
| 238 | 239 | foreach( ['messages', 'rules'] as $key ) { |
| 239 | - if( empty( $validation[$key] ))continue; |
|
| 240 | + if( empty( $validation[$key] )) { |
|
| 241 | + continue; |
|
| 242 | + } |
|
| 240 | 243 | foreach( $validation[$key] as $id => $value ) { |
| 241 | 244 | $validation[$key][$this->normalizeFieldName( $id, ['slug' => $id], $parentId )] = $value; |
| 242 | 245 | unset( $validation[$key][$id] ); |
@@ -252,8 +255,11 @@ discard block |
||
| 252 | 255 | { |
| 253 | 256 | $fields = &$metabox['fields']; |
| 254 | 257 | $depends = array_column( $fields, 'depends' ); |
| 255 | - array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) { |
|
| 256 | - if( empty( $value ))return; |
|
| 258 | + array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) |
|
| 259 | + { |
|
| 260 | + if( empty( $value )) { |
|
| 261 | + return; |
|
| 262 | + } |
|
| 257 | 263 | $dependency = array_search( $value, array_column( $fields, 'id' )); |
| 258 | 264 | $fields[$index]['attributes']['data-depends'] = $value; |
| 259 | 265 | if( !$this->getMetaValue( $fields[$dependency]['slug'], '', $metabox['slug'] )) { |
@@ -44,16 +44,16 @@ discard block |
||
| 44 | 44 | // @todo: run GateKeeper to check dependencies and capability (make sure it it run on the correct hook!) |
| 45 | 45 | // if( !is_plugin_active( 'meta-box/meta-box.php' ))return; |
| 46 | 46 | |
| 47 | - $this->normalize( $this->app->config[static::ID] ); |
|
| 47 | + $this->normalize( $this->app->config[ static::ID ] ); |
|
| 48 | 48 | |
| 49 | - add_action( 'admin_menu', [$this, 'addPage'] ); |
|
| 50 | - add_action( 'pollux/'.static::ID.'/init', [$this, 'addSubmitMetaBox'] ); |
|
| 51 | - add_action( 'current_screen', [$this, 'register'] ); |
|
| 52 | - add_action( 'admin_menu', [$this, 'registerSetting'] ); |
|
| 53 | - add_action( 'pollux/'.static::ID.'/init', [$this, 'reset'] ); |
|
| 54 | - add_action( 'admin_print_footer_scripts', [$this, 'renderFooterScript'] ); |
|
| 55 | - add_filter( 'pollux/'.static::ID.'/instruction', [$this, 'filterInstruction'], 10, 3 ); |
|
| 56 | - add_filter( 'pollux/'.static::ID.'/before/instructions', [$this, 'filterBeforeInstructions'] ); |
|
| 49 | + add_action( 'admin_menu', [ $this, 'addPage' ] ); |
|
| 50 | + add_action( 'pollux/' . static::ID . '/init', [ $this, 'addSubmitMetaBox' ] ); |
|
| 51 | + add_action( 'current_screen', [ $this, 'register' ] ); |
|
| 52 | + add_action( 'admin_menu', [ $this, 'registerSetting' ] ); |
|
| 53 | + add_action( 'pollux/' . static::ID . '/init', [ $this, 'reset' ] ); |
|
| 54 | + add_action( 'admin_print_footer_scripts', [ $this, 'renderFooterScript' ] ); |
|
| 55 | + add_filter( 'pollux/' . static::ID . '/instruction', [ $this, 'filterInstruction' ], 10, 3 ); |
|
| 56 | + add_filter( 'pollux/' . static::ID . '/before/instructions', [ $this, 'filterBeforeInstructions' ] ); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -67,10 +67,10 @@ discard block |
||
| 67 | 67 | __( 'Site Settings', 'pollux' ), |
| 68 | 68 | 'edit_theme_options', |
| 69 | 69 | static::id(), |
| 70 | - [$this, 'renderPage'], |
|
| 70 | + [ $this, 'renderPage' ], |
|
| 71 | 71 | 'dashicons-screenoptions', |
| 72 | 72 | 1313 |
| 73 | - ])); |
|
| 73 | + ] ) ); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -82,11 +82,11 @@ discard block |
||
| 82 | 82 | call_user_func_array( 'add_meta_box', $this->filter( 'metabox/submit', [ |
| 83 | 83 | 'submitdiv', |
| 84 | 84 | __( 'Save Settings', 'pollux' ), |
| 85 | - [$this, 'renderSubmitMetaBox'], |
|
| 85 | + [ $this, 'renderSubmitMetaBox' ], |
|
| 86 | 86 | $this->hook, |
| 87 | 87 | 'side', |
| 88 | 88 | 'high', |
| 89 | - ])); |
|
| 89 | + ] ) ); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | public function filterInstruction( $instruction, array $field, array $metabox ) |
| 107 | 107 | { |
| 108 | - return sprintf( "SiteMeta::%s('%s');", $metabox['slug'], $field['slug'] ); |
|
| 108 | + return sprintf( "SiteMeta::%s('%s');", $metabox[ 'slug' ], $field[ 'slug' ] ); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -115,10 +115,10 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | public function filterSavedSettings( $settings ) |
| 117 | 117 | { |
| 118 | - if( is_null( $settings )) { |
|
| 119 | - $settings = []; |
|
| 118 | + if( is_null( $settings ) ) { |
|
| 119 | + $settings = [ ]; |
|
| 120 | 120 | } |
| 121 | - return $this->filter( 'save', array_merge( $this->getSettings(), $settings )); |
|
| 121 | + return $this->filter( 'save', array_merge( $this->getSettings(), $settings ) ); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -138,14 +138,14 @@ discard block |
||
| 138 | 138 | */ |
| 139 | 139 | public function register() |
| 140 | 140 | { |
| 141 | - if(( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
| 141 | + if( ( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
| 142 | 142 | foreach( parent::register() as $metabox ) { |
| 143 | 143 | new RWMetaBox( $metabox, static::ID, $this ); |
| 144 | 144 | } |
| 145 | 145 | add_screen_option( 'layout_columns', [ |
| 146 | 146 | 'max' => 2, |
| 147 | 147 | 'default' => 2, |
| 148 | - ]); |
|
| 148 | + ] ); |
|
| 149 | 149 | $this->action( 'init' ); |
| 150 | 150 | } |
| 151 | 151 | |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | public function registerSetting() |
| 157 | 157 | { |
| 158 | - register_setting( static::id(), static::id(), [$this, 'filterSavedSettings'] ); |
|
| 158 | + register_setting( static::id(), static::id(), [ $this, 'filterSavedSettings' ] ); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -164,12 +164,12 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | public function renderFooterScript() |
| 166 | 166 | { |
| 167 | - if(( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
| 167 | + if( ( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
| 168 | 168 | $this->render( 'settings/script', [ |
| 169 | 169 | 'confirm' => __( 'Are you sure want to do this?', 'pollux' ), |
| 170 | 170 | 'hook' => $this->hook, |
| 171 | 171 | 'id' => static::id(), |
| 172 | - ]); |
|
| 172 | + ] ); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | 'columns' => get_current_screen()->get_columns(), |
| 183 | 183 | 'heading' => __( 'Site Settings', 'pollux' ), |
| 184 | 184 | 'id' => static::id(), |
| 185 | - ]); |
|
| 185 | + ] ); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -199,9 +199,9 @@ discard block |
||
| 199 | 199 | ]; |
| 200 | 200 | $this->render( 'settings/submit', [ |
| 201 | 201 | 'reset' => __( 'Reset all', 'pollux' ), |
| 202 | - 'reset_url' => esc_url( add_query_arg( $query, admin_url( $pagenow ))), |
|
| 202 | + 'reset_url' => esc_url( add_query_arg( $query, admin_url( $pagenow ) ) ), |
|
| 203 | 203 | 'submit' => get_submit_button( __( 'Save', 'pollux' ), 'primary', 'submit', false ), |
| 204 | - ]); |
|
| 204 | + ] ); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -213,15 +213,15 @@ discard block |
||
| 213 | 213 | if( filter_input( INPUT_GET, 'page' ) !== static::id() |
| 214 | 214 | || filter_input( INPUT_GET, 'action' ) !== 'reset' |
| 215 | 215 | )return; |
| 216 | - if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook )) { |
|
| 216 | + if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook ) ) { |
|
| 217 | 217 | update_option( static::id(), $this->getDefaults() ); |
| 218 | 218 | add_settings_error( static::id(), 'reset', __( 'Reset successful.', 'pollux' ), 'updated' ); |
| 219 | 219 | } |
| 220 | 220 | else { |
| 221 | - add_settings_error( static::id(), 'failed', __( 'Failed to reset. Please try again.', 'pollux' )); |
|
| 221 | + add_settings_error( static::id(), 'failed', __( 'Failed to reset. Please try again.', 'pollux' ) ); |
|
| 222 | 222 | } |
| 223 | 223 | set_transient( 'settings_errors', get_settings_errors(), 30 ); |
| 224 | - wp_safe_redirect( add_query_arg( 'settings-updated', 'true', wp_get_referer() )); |
|
| 224 | + wp_safe_redirect( add_query_arg( 'settings-updated', 'true', wp_get_referer() ) ); |
|
| 225 | 225 | exit; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | protected function filterArrayByKey( array $array, $key ) |
| 233 | 233 | { |
| 234 | 234 | return array_filter( $array, function( $value ) use( $key ) { |
| 235 | - return !empty( $value[$key] ); |
|
| 235 | + return !empty( $value[ $key ] ); |
|
| 236 | 236 | }); |
| 237 | 237 | } |
| 238 | 238 | |
@@ -245,11 +245,11 @@ discard block |
||
| 245 | 245 | |
| 246 | 246 | array_walk( $metaboxes, function( &$metabox ) { |
| 247 | 247 | $fields = array_map( function( $field ) { |
| 248 | - $field = wp_parse_args( $field, ['std' => ''] ); |
|
| 249 | - return [$field['slug'] => $field['std']]; |
|
| 250 | - }, $this->filterArrayByKey( $metabox['fields'], 'slug' )); |
|
| 248 | + $field = wp_parse_args( $field, [ 'std' => '' ] ); |
|
| 249 | + return [ $field[ 'slug' ] => $field[ 'std' ] ]; |
|
| 250 | + }, $this->filterArrayByKey( $metabox[ 'fields' ], 'slug' ) ); |
|
| 251 | 251 | $metabox = [ |
| 252 | - $metabox['slug'] => call_user_func_array( 'array_merge', $fields ), |
|
| 252 | + $metabox[ 'slug' ] => call_user_func_array( 'array_merge', $fields ), |
|
| 253 | 253 | ]; |
| 254 | 254 | }); |
| 255 | 255 | return call_user_func_array( 'array_merge', $metaboxes ); |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | */ |
| 268 | 268 | protected function normalizeFieldName( $name, array $data, $parentId ) |
| 269 | 269 | { |
| 270 | - return sprintf( '%s[%s][%s]', static::id(), $parentId, $data['slug'] ); |
|
| 270 | + return sprintf( '%s[%s][%s]', static::id(), $parentId, $data[ 'slug' ] ); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -138,7 +138,9 @@ discard block |
||
| 138 | 138 | */ |
| 139 | 139 | public function register() |
| 140 | 140 | { |
| 141 | - if(( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
| 141 | + if(( new Helper )->getCurrentScreen()->id != $this->hook ) { |
|
| 142 | + return; |
|
| 143 | + } |
|
| 142 | 144 | foreach( parent::register() as $metabox ) { |
| 143 | 145 | new RWMetaBox( $metabox, static::ID, $this ); |
| 144 | 146 | } |
@@ -164,7 +166,9 @@ discard block |
||
| 164 | 166 | */ |
| 165 | 167 | public function renderFooterScript() |
| 166 | 168 | { |
| 167 | - if(( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
| 169 | + if(( new Helper )->getCurrentScreen()->id != $this->hook ) { |
|
| 170 | + return; |
|
| 171 | + } |
|
| 168 | 172 | $this->render( 'settings/script', [ |
| 169 | 173 | 'confirm' => __( 'Are you sure want to do this?', 'pollux' ), |
| 170 | 174 | 'hook' => $this->hook, |
@@ -212,7 +216,9 @@ discard block |
||
| 212 | 216 | { |
| 213 | 217 | if( filter_input( INPUT_GET, 'page' ) !== static::id() |
| 214 | 218 | || filter_input( INPUT_GET, 'action' ) !== 'reset' |
| 215 | - )return; |
|
| 219 | + ) { |
|
| 220 | + return; |
|
| 221 | + } |
|
| 216 | 222 | if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook )) { |
| 217 | 223 | update_option( static::id(), $this->getDefaults() ); |
| 218 | 224 | add_settings_error( static::id(), 'reset', __( 'Reset successful.', 'pollux' ), 'updated' ); |
@@ -231,7 +237,8 @@ discard block |
||
| 231 | 237 | */ |
| 232 | 238 | protected function filterArrayByKey( array $array, $key ) |
| 233 | 239 | { |
| 234 | - return array_filter( $array, function( $value ) use( $key ) { |
|
| 240 | + return array_filter( $array, function( $value ) use( $key ) |
|
| 241 | + { |
|
| 235 | 242 | return !empty( $value[$key] ); |
| 236 | 243 | }); |
| 237 | 244 | } |
@@ -243,8 +250,10 @@ discard block |
||
| 243 | 250 | { |
| 244 | 251 | $metaboxes = $this->filterArrayByKey( $this->metaboxes, 'slug' ); |
| 245 | 252 | |
| 246 | - array_walk( $metaboxes, function( &$metabox ) { |
|
| 247 | - $fields = array_map( function( $field ) { |
|
| 253 | + array_walk( $metaboxes, function( &$metabox ) |
|
| 254 | + { |
|
| 255 | + $fields = array_map( function( $field ) |
|
| 256 | + { |
|
| 248 | 257 | $field = wp_parse_args( $field, ['std' => ''] ); |
| 249 | 258 | return [$field['slug'] => $field['std']]; |
| 250 | 259 | }, $this->filterArrayByKey( $metabox['fields'], 'slug' )); |
@@ -19,12 +19,12 @@ discard block |
||
| 19 | 19 | $this->pollux_caller = $caller; |
| 20 | 20 | $this->pollux_id = $id; |
| 21 | 21 | |
| 22 | - remove_action( 'add_meta_boxes', [$this, 'add_meta_boxes'] ); |
|
| 23 | - remove_action( 'save_post_post', [$this, 'save_post'] ); |
|
| 22 | + remove_action( 'add_meta_boxes', [ $this, 'add_meta_boxes' ] ); |
|
| 23 | + remove_action( 'save_post_post', [ $this, 'save_post' ] ); |
|
| 24 | 24 | |
| 25 | - add_action( 'pollux/archives/init', [$this, 'add_meta_boxes'] ); |
|
| 26 | - add_action( 'pollux/settings/init', [$this, 'add_meta_boxes'] ); |
|
| 27 | - add_filter( 'rwmb_field_meta', [$this, '_get_field_meta'], 10, 3 ); |
|
| 25 | + add_action( 'pollux/archives/init', [ $this, 'add_meta_boxes' ] ); |
|
| 26 | + add_action( 'pollux/settings/init', [ $this, 'add_meta_boxes' ] ); |
|
| 27 | + add_filter( 'rwmb_field_meta', [ $this, '_get_field_meta' ], 10, 3 ); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -35,13 +35,13 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function _get_field_meta( $meta, array $field, $saved ) |
| 37 | 37 | { |
| 38 | - if( !$this->is_edit_screen() || !empty(( new Helper )->toArray( $meta )) || empty( $field['slug'] )) { |
|
| 38 | + if( !$this->is_edit_screen() || !empty( ( new Helper )->toArray( $meta ) ) || empty( $field[ 'slug' ] ) ) { |
|
| 39 | 39 | return $meta; |
| 40 | 40 | } |
| 41 | - $meta = call_user_func( [RWMB_Field::get_class_name( $field ), 'esc_meta'], ( $saved |
|
| 42 | - ? $this->pollux_caller->getMetaValue( $field['slug'], $meta, $this->meta_box['slug'] ) |
|
| 43 | - : $field['std'] |
|
| 44 | - )); |
|
| 41 | + $meta = call_user_func( [ RWMB_Field::get_class_name( $field ), 'esc_meta' ], ( $saved |
|
| 42 | + ? $this->pollux_caller->getMetaValue( $field[ 'slug' ], $meta, $this->meta_box[ 'slug' ] ) |
|
| 43 | + : $field[ 'std' ] |
|
| 44 | + ) ); |
|
| 45 | 45 | return $this->_normalize_field_meta( $meta, $field ); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -51,14 +51,14 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | public function _normalize_field_meta( $meta, array $field ) |
| 53 | 53 | { |
| 54 | - if( !empty( $meta ) && is_array( $meta )) { |
|
| 54 | + if( !empty( $meta ) && is_array( $meta ) ) { |
|
| 55 | 55 | return $meta; |
| 56 | 56 | } |
| 57 | - if( $field['clone'] ) { |
|
| 58 | - return ['']; |
|
| 57 | + if( $field[ 'clone' ] ) { |
|
| 58 | + return [ '' ]; |
|
| 59 | 59 | } |
| 60 | - if( $field['multiple'] ) { |
|
| 61 | - return []; |
|
| 60 | + if( $field[ 'multiple' ] ) { |
|
| 61 | + return [ ]; |
|
| 62 | 62 | } |
| 63 | 63 | return $meta; |
| 64 | 64 | } |
@@ -71,12 +71,12 @@ discard block |
||
| 71 | 71 | public function add_meta_boxes() |
| 72 | 72 | { |
| 73 | 73 | add_meta_box( |
| 74 | - $this->meta_box['id'], |
|
| 75 | - $this->meta_box['title'], |
|
| 76 | - [$this, 'show'], |
|
| 74 | + $this->meta_box[ 'id' ], |
|
| 75 | + $this->meta_box[ 'title' ], |
|
| 76 | + [ $this, 'show' ], |
|
| 77 | 77 | null, |
| 78 | - $this->meta_box['context'], |
|
| 79 | - $this->meta_box['priority'] |
|
| 78 | + $this->meta_box[ 'context' ], |
|
| 79 | + $this->meta_box[ 'priority' ] |
|
| 80 | 80 | ); |
| 81 | 81 | } |
| 82 | 82 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | public function is_saved() |
| 95 | 95 | { |
| 96 | 96 | foreach( array_column( $this->fields, 'slug' ) as $field ) { |
| 97 | - if( !is_null( $this->pollux_caller->getMetaValue( $field, null, $this->meta_box['slug'] ))) { |
|
| 97 | + if( !is_null( $this->pollux_caller->getMetaValue( $field, null, $this->meta_box[ 'slug' ] ) ) ) { |
|
| 98 | 98 | return true; |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | public static function normalize( $metabox ) |
| 109 | 109 | { |
| 110 | - unset( $metabox['post_types'] ); |
|
| 111 | - return wp_parse_args( $metabox, ['slug' => ''] ); |
|
| 110 | + unset( $metabox[ 'post_types' ] ); |
|
| 111 | + return wp_parse_args( $metabox, [ 'slug' => '' ] ); |
|
| 112 | 112 | } |
| 113 | 113 | } |