@@ -134,7 +134,9 @@ discard block |
||
| 134 | 134 | */ |
| 135 | 135 | public function register() |
| 136 | 136 | { |
| 137 | - if(( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
| 137 | + if(( new Helper )->getCurrentScreen()->id != $this->hook ) { |
|
| 138 | + return; |
|
| 139 | + } |
|
| 138 | 140 | foreach( parent::register() as $metabox ) { |
| 139 | 141 | new RWMetaBox( $metabox ); |
| 140 | 142 | } |
@@ -206,7 +208,9 @@ discard block |
||
| 206 | 208 | { |
| 207 | 209 | if( filter_input( INPUT_GET, 'page' ) !== $this->id |
| 208 | 210 | || filter_input( INPUT_GET, 'action' ) !== 'reset' |
| 209 | - )return; |
|
| 211 | + ) { |
|
| 212 | + return; |
|
| 213 | + } |
|
| 210 | 214 | if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook )) { |
| 211 | 215 | update_option( $this->id, $this->getDefaults() ); |
| 212 | 216 | return add_settings_error( $this->id, 'reset', __( 'Settings reset to defaults.', 'pollux' ), 'updated' ); |
@@ -220,7 +224,8 @@ discard block |
||
| 220 | 224 | */ |
| 221 | 225 | protected function filterArrayByKey( array $array, $key ) |
| 222 | 226 | { |
| 223 | - return array_filter( $array, function( $value ) use( $key ) { |
|
| 227 | + return array_filter( $array, function( $value ) use( $key ) |
|
| 228 | + { |
|
| 224 | 229 | return !empty( $value[$key] ); |
| 225 | 230 | }); |
| 226 | 231 | } |
@@ -232,8 +237,10 @@ discard block |
||
| 232 | 237 | { |
| 233 | 238 | $metaboxes = $this->filterArrayByKey( $this->metaboxes, 'slug' ); |
| 234 | 239 | |
| 235 | - array_walk( $metaboxes, function( &$metabox ) { |
|
| 236 | - $fields = array_map( function( $field ) { |
|
| 240 | + array_walk( $metaboxes, function( &$metabox ) |
|
| 241 | + { |
|
| 242 | + $fields = array_map( function( $field ) |
|
| 243 | + { |
|
| 237 | 244 | $field = wp_parse_args( $field, ['std' => ''] ); |
| 238 | 245 | return [$field['slug'] => $field['std']]; |
| 239 | 246 | }, $this->filterArrayByKey( $metabox['fields'], 'slug' )); |
@@ -48,10 +48,14 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | public function filterByTaxonomy( WP_Query $query ) |
| 50 | 50 | { |
| 51 | - if( !is_admin() || ( new Helper )->getCurrentScreen()->base != 'edit' )return; |
|
| 51 | + if( !is_admin() || ( new Helper )->getCurrentScreen()->base != 'edit' ) { |
|
| 52 | + return; |
|
| 53 | + } |
|
| 52 | 54 | $vars = &$query->query_vars; |
| 53 | 55 | foreach( array_keys( $this->taxonomies ) as $taxonomy ) { |
| 54 | - if( !isset( $vars[$taxonomy] ))return; |
|
| 56 | + if( !isset( $vars[$taxonomy] )) { |
|
| 57 | + return; |
|
| 58 | + } |
|
| 55 | 59 | if( $term = get_term_by( 'id', $vars[$taxonomy], $taxonomy )) { |
| 56 | 60 | $vars[$taxonomy] = $term->slug; |
| 57 | 61 | } |
@@ -67,7 +71,9 @@ discard block |
||
| 67 | 71 | { |
| 68 | 72 | global $wp_query; |
| 69 | 73 | foreach( $this->taxonomies as $taxonomy => $args ) { |
| 70 | - if( !in_array( get_current_screen()->post_type, $args['post_types'] ))continue; |
|
| 74 | + if( !in_array( get_current_screen()->post_type, $args['post_types'] )) { |
|
| 75 | + continue; |
|
| 76 | + } |
|
| 71 | 77 | $selected = isset( $wp_query->query[$taxonomy] ) |
| 72 | 78 | ? $wp_query->query[$taxonomy] |
| 73 | 79 | : false; |
@@ -88,7 +94,8 @@ discard block |
||
| 88 | 94 | */ |
| 89 | 95 | public function register() |
| 90 | 96 | { |
| 91 | - array_walk( $this->taxonomies, function( $args, $taxonomy ) { |
|
| 97 | + array_walk( $this->taxonomies, function( $args, $taxonomy ) |
|
| 98 | + { |
|
| 92 | 99 | register_taxonomy( $taxonomy, $args['post_types'], array_diff_key( $args, array_flip( static::CUSTOM_KEYS ))); |
| 93 | 100 | foreach( $args['post_types'] as $type ) { |
| 94 | 101 | register_taxonomy_for_object_type( $taxonomy, $type ); |
@@ -21,7 +21,8 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | public function validate( array $conditions ) |
| 23 | 23 | { |
| 24 | - array_walk( $conditions, function( &$value, $key ) { |
|
| 24 | + array_walk( $conditions, function( &$value, $key ) |
|
| 25 | + { |
|
| 25 | 26 | $method = ( new Helper )->buildMethodName( $key, 'validate' ); |
| 26 | 27 | $value = method_exists( $this, $method ) |
| 27 | 28 | ? $this->$method( $value ) |
@@ -41,7 +42,8 @@ discard block |
||
| 41 | 42 | foreach( $conditions as $key ) { |
| 42 | 43 | $conditions[str_replace( '!', '', $key )] = substr( $key, 0, 1 ) == '!' ? 0 : 1; |
| 43 | 44 | } |
| 44 | - $conditions = array_filter( $conditions, function( $key ) { |
|
| 45 | + $conditions = array_filter( $conditions, function( $key ) |
|
| 46 | + { |
|
| 45 | 47 | return !is_numeric( $key ); |
| 46 | 48 | }, ARRAY_FILTER_USE_KEY ); |
| 47 | 49 | } |
@@ -22,9 +22,12 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | protected function addInstructions() |
| 24 | 24 | { |
| 25 | - if( !count( array_filter( $this->metaboxes, function( $metabox ) { |
|
| 25 | + if( !count( array_filter( $this->metaboxes, function( $metabox ) |
|
| 26 | + { |
|
| 26 | 27 | return $this->show( false, $metabox ); |
| 27 | - })))return; |
|
| 28 | + }))) { |
|
| 29 | + return; |
|
| 30 | + } |
|
| 28 | 31 | $this->metaboxes[] = [ |
| 29 | 32 | 'id' => 'infodiv', |
| 30 | 33 | 'post_types' => $this->getPostTypes(), |
@@ -44,8 +47,10 @@ discard block |
||
| 44 | 47 | */ |
| 45 | 48 | protected function generateInstructions() |
| 46 | 49 | { |
| 47 | - return array_reduce( $this->getInstructions(), function( $html, $metabox ) { |
|
| 48 | - $fields = array_reduce( array_column( $metabox['fields'], 'slug' ), function( $html, $slug ) use( $metabox ) { |
|
| 50 | + return array_reduce( $this->getInstructions(), function( $html, $metabox ) |
|
| 51 | + { |
|
| 52 | + $fields = array_reduce( array_column( $metabox['fields'], 'slug' ), function( $html, $slug ) use( $metabox ) |
|
| 53 | + { |
|
| 49 | 54 | $hook = sprintf( 'pollux/%s/instruction', ( new Helper )->getClassname() ); |
| 50 | 55 | return $html . apply_filters( $hook, "PostMeta::get('{$slug}');", $slug, $metabox['slug'] ) . PHP_EOL; |
| 51 | 56 | }); |
@@ -61,7 +66,8 @@ discard block |
||
| 61 | 66 | */ |
| 62 | 67 | protected function getInstructions() |
| 63 | 68 | { |
| 64 | - return array_filter( $this->metaboxes, function( $metabox ) { |
|
| 69 | + return array_filter( $this->metaboxes, function( $metabox ) |
|
| 70 | + { |
|
| 65 | 71 | return $this->validate( $metabox['condition'] ) |
| 66 | 72 | && $this->hasPostType( $metabox ); |
| 67 | 73 | }); |
@@ -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'] )) { |