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