@@ -13,10 +13,10 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | public function buildClassName( $name, $path = '' ) |
| 15 | 15 | { |
| 16 | - $className = array_map( 'ucfirst', array_map( 'strtolower', preg_split( '/[-_]/', $name ))); |
|
| 16 | + $className = array_map( 'ucfirst', array_map( 'strtolower', preg_split( '/[-_]/', $name ) ) ); |
|
| 17 | 17 | $className = implode( '', $className ); |
| 18 | 18 | return !empty( $path ) |
| 19 | - ? str_replace( '\\\\', '\\', sprintf( '%s\%s', $path, $className )) |
|
| 19 | + ? str_replace( '\\\\', '\\', sprintf( '%s\%s', $path, $className ) ) |
|
| 20 | 20 | : $className; |
| 21 | 21 | } |
| 22 | 22 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | public function buildMethodName( $name, $prefix = 'get' ) |
| 29 | 29 | { |
| 30 | - return lcfirst( $this->buildClassName( $prefix . '-' . $name )); |
|
| 30 | + return lcfirst( $this->buildClassName( $prefix . '-' . $name ) ); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | public function getCurrentScreen() |
| 64 | 64 | { |
| 65 | 65 | global $current_screen, $pagenow; |
| 66 | - if( isset( $current_screen )) { |
|
| 66 | + if( isset( $current_screen ) ) { |
|
| 67 | 67 | $current_screen->pagenow = $pagenow; |
| 68 | 68 | return $current_screen; |
| 69 | 69 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public function startsWith( $needle, $haystack ) |
| 83 | 83 | { |
| 84 | - return substr( $haystack, 0, strlen( $needle )) === $needle; |
|
| 84 | + return substr( $haystack, 0, strlen( $needle ) ) === $needle; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function filterWordPressFooter( $text ) |
| 27 | 27 | { |
| 28 | - if( $this->app->config['remove_wordpress_footer'] )return; |
|
| 28 | + if( $this->app->config[ 'remove_wordpress_footer' ] )return; |
|
| 29 | 29 | return $text; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | { |
| 38 | 38 | $screen = ( new Helper )->getCurrentScreen(); |
| 39 | 39 | |
| 40 | - if(( new Helper )->endsWith( '_archive', $screen->id ) && $screen->pagenow == 'edit.php' ) { |
|
| 40 | + if( ( new Helper )->endsWith( '_archive', $screen->id ) && $screen->pagenow == 'edit.php' ) { |
|
| 41 | 41 | wp_enqueue_script( 'editor-expand' ); |
| 42 | 42 | wp_enqueue_script( 'common' ); |
| 43 | 43 | wp_enqueue_script( 'wp-lists' ); |
@@ -47,24 +47,24 @@ discard block |
||
| 47 | 47 | wp_enqueue_script( 'jquery-touch-punch' ); |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | - if( $screen->id == sprintf( 'toplevel_page_%s', Settings::id() )) { |
|
| 50 | + if( $screen->id == sprintf( 'toplevel_page_%s', Settings::id() ) ) { |
|
| 51 | 51 | wp_enqueue_script( 'common' ); |
| 52 | 52 | wp_enqueue_script( 'wp-lists' ); |
| 53 | 53 | wp_enqueue_script( 'postbox' ); |
| 54 | 54 | } |
| 55 | 55 | wp_enqueue_style( 'pollux/main.css', |
| 56 | 56 | $this->app->url( 'assets/main.css' ), |
| 57 | - apply_filters( 'pollux/enqueue/css/deps', [] ), |
|
| 57 | + apply_filters( 'pollux/enqueue/css/deps', [ ] ), |
|
| 58 | 58 | $this->app->version |
| 59 | 59 | ); |
| 60 | 60 | wp_enqueue_script( 'pollux/main.js', |
| 61 | 61 | $this->app->url( 'assets/main.js' ), |
| 62 | - apply_filters( 'pollux/enqueue/js/deps', [] ), |
|
| 62 | + apply_filters( 'pollux/enqueue/js/deps', [ ] ), |
|
| 63 | 63 | $this->app->version |
| 64 | 64 | ); |
| 65 | 65 | wp_localize_script( 'pollux/main.js', |
| 66 | 66 | apply_filters( 'pollux/enqueue/js/localize/name', $this->app->id ), |
| 67 | - apply_filters( 'pollux/enqueue/js/localize/variables', [] ) |
|
| 67 | + apply_filters( 'pollux/enqueue/js/localize/variables', [ ] ) |
|
| 68 | 68 | ); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -74,11 +74,11 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function removeDashboardWidgets() |
| 76 | 76 | { |
| 77 | - if( !$this->app->config['remove_dashboard_widgets'] )return; |
|
| 77 | + if( !$this->app->config[ 'remove_dashboard_widgets' ] )return; |
|
| 78 | 78 | $widgets = apply_filters( 'pollux/dashoard/widgets', [ |
| 79 | 79 | 'dashboard_primary', |
| 80 | 80 | 'dashboard_quick_press', |
| 81 | - ]); |
|
| 81 | + ] ); |
|
| 82 | 82 | foreach( $widgets as $widget ) { |
| 83 | 83 | remove_meta_box( $widget, 'dashboard', 'normal' ); |
| 84 | 84 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | public function removeWordPressMenu() |
| 92 | 92 | { |
| 93 | - if( !$this->app->config['remove_wordpress_menu'] )return; |
|
| 93 | + if( !$this->app->config[ 'remove_wordpress_menu' ] )return; |
|
| 94 | 94 | global $wp_admin_bar; |
| 95 | 95 | $wp_admin_bar->remove_menu( 'wp-logo' ); |
| 96 | 96 | } |
@@ -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,15 +66,15 @@ 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 | $instructions = $this->initInstructions(); |
| 71 | - if( is_array( $instructions )) { |
|
| 71 | + if( is_array( $instructions ) ) { |
|
| 72 | 72 | $this->normalize( $instructions ); |
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | $metaboxes = func_num_args() |
| 76 | - ? ( new Helper )->toArray( func_get_arg(0) ) |
|
| 77 | - : []; |
|
| 76 | + ? ( new Helper )->toArray( func_get_arg( 0 ) ) |
|
| 77 | + : [ ]; |
|
| 78 | 78 | return array_merge( $metaboxes, $this->metaboxes ); |
| 79 | 79 | } |
| 80 | 80 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function renderField( $html, $field ) |
| 86 | 86 | { |
| 87 | - return $this->validate( $field['condition'] ) |
|
| 87 | + return $this->validate( $field[ 'condition' ] ) |
|
| 88 | 88 | ? $html |
| 89 | 89 | : ''; |
| 90 | 90 | } |
@@ -96,11 +96,11 @@ discard block |
||
| 96 | 96 | public function show( $bool, array $metabox ) |
| 97 | 97 | { |
| 98 | 98 | if( defined( 'DOING_AJAX' ) |
| 99 | - || !isset( $metabox['condition'] ) |
|
| 100 | - || !$this->hasPostType( $metabox )) { |
|
| 99 | + || !isset( $metabox[ 'condition' ] ) |
|
| 100 | + || !$this->hasPostType( $metabox ) ) { |
|
| 101 | 101 | return $bool; |
| 102 | 102 | } |
| 103 | - return $this->validate( $metabox['condition'] ); |
|
| 103 | + return $this->validate( $metabox[ 'condition' ] ); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | protected function getPostId() |
| 110 | 110 | { |
| 111 | - if( !( $postId = filter_input( INPUT_GET, 'post' ))) { |
|
| 111 | + if( !( $postId = filter_input( INPUT_GET, 'post' ) ) ) { |
|
| 112 | 112 | $postId = filter_input( INPUT_POST, 'post_ID' ); |
| 113 | 113 | } |
| 114 | 114 | return intval( $postId ); |
@@ -121,10 +121,10 @@ discard block |
||
| 121 | 121 | { |
| 122 | 122 | return array_unique( iterator_to_array( |
| 123 | 123 | new RecursiveIteratorIterator( |
| 124 | - new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' )) |
|
| 124 | + new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' ) ) |
|
| 125 | 125 | ), |
| 126 | 126 | false |
| 127 | - )); |
|
| 127 | + ) ); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | { |
| 135 | 135 | return PostMeta::get( $key, [ |
| 136 | 136 | 'id' => $this->getPostId(), |
| 137 | - ]); |
|
| 137 | + ] ); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -142,26 +142,26 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | protected function hasPostType( array $metabox ) |
| 144 | 144 | { |
| 145 | - if( !isset( $metabox['post_types'] )) { |
|
| 145 | + if( !isset( $metabox[ 'post_types' ] ) ) { |
|
| 146 | 146 | return true; |
| 147 | 147 | } |
| 148 | - return in_array( get_post_type( $this->getPostId() ), $metabox['post_types'] ); |
|
| 148 | + return in_array( get_post_type( $this->getPostId() ), $metabox[ 'post_types' ] ); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
| 152 | 152 | * @return void |
| 153 | 153 | */ |
| 154 | - protected function normalize( array $metaboxes, array $defaults = [] ) |
|
| 154 | + protected function normalize( array $metaboxes, array $defaults = [ ] ) |
|
| 155 | 155 | { |
| 156 | 156 | foreach( $metaboxes as $id => $metabox ) { |
| 157 | 157 | $data = wp_parse_args( $defaults, [ |
| 158 | - 'condition' => [], |
|
| 159 | - 'fields' => [], |
|
| 158 | + 'condition' => [ ], |
|
| 159 | + 'fields' => [ ], |
|
| 160 | 160 | 'id' => $id, |
| 161 | 161 | 'slug' => $id, |
| 162 | - 'validation' => [], |
|
| 163 | - ]); |
|
| 164 | - $this->metaboxes[] = $this->setDependencies( |
|
| 162 | + 'validation' => [ ], |
|
| 163 | + ] ); |
|
| 164 | + $this->metaboxes[ ] = $this->setDependencies( |
|
| 165 | 165 | $this->normalizeThis( $metabox, $data, $id ) |
| 166 | 166 | ); |
| 167 | 167 | } |
@@ -195,10 +195,10 @@ discard block |
||
| 195 | 195 | protected function normalizeFields( array $fields, array $data, $parentId ) |
| 196 | 196 | { |
| 197 | 197 | return array_map( function( $id, $field ) use( $parentId ) { |
| 198 | - $defaults = [ |
|
| 199 | - 'attributes' => [], |
|
| 198 | + $defaults = [ |
|
| 199 | + 'attributes' => [ ], |
|
| 200 | 200 | 'class' => '', |
| 201 | - 'condition' => [], |
|
| 201 | + 'condition' => [ ], |
|
| 202 | 202 | 'depends' => '', |
| 203 | 203 | 'field_name' => $id, |
| 204 | 204 | 'id' => $id, |
@@ -232,11 +232,11 @@ discard block |
||
| 232 | 232 | */ |
| 233 | 233 | protected function normalizeValidation( array $validation, array $data, $parentId ) |
| 234 | 234 | { |
| 235 | - foreach( ['messages', 'rules'] as $key ) { |
|
| 236 | - if( empty( $validation[$key] ))continue; |
|
| 237 | - foreach( $validation[$key] as $id => $value ) { |
|
| 238 | - $validation[$key][$this->normalizeFieldName( $id, ['slug' => $id], $parentId )] = $value; |
|
| 239 | - unset( $validation[$key][$id] ); |
|
| 235 | + foreach( [ 'messages', 'rules' ] as $key ) { |
|
| 236 | + if( empty( $validation[ $key ] ) )continue; |
|
| 237 | + foreach( $validation[ $key ] as $id => $value ) { |
|
| 238 | + $validation[ $key ][ $this->normalizeFieldName( $id, [ 'slug' => $id ], $parentId ) ] = $value; |
|
| 239 | + unset( $validation[ $key ][ $id ] ); |
|
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | 242 | return $validation; |
@@ -247,14 +247,14 @@ discard block |
||
| 247 | 247 | */ |
| 248 | 248 | protected function setDependencies( array $metabox ) |
| 249 | 249 | { |
| 250 | - $fields = &$metabox['fields']; |
|
| 250 | + $fields = &$metabox[ 'fields' ]; |
|
| 251 | 251 | $depends = array_column( $fields, 'depends' ); |
| 252 | 252 | array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) { |
| 253 | - if( empty( $value ))return; |
|
| 254 | - $dependency = array_search( $value, array_column( $fields, 'id' )); |
|
| 255 | - $fields[$index]['attributes']['data-depends'] = $value; |
|
| 256 | - if( !$this->getValue( $fields[$dependency]['slug'], $metabox['slug'] )) { |
|
| 257 | - $fields[$index]['class'] = trim( 'hidden ' . $fields[$index]['class'] ); |
|
| 253 | + if( empty( $value ) )return; |
|
| 254 | + $dependency = array_search( $value, array_column( $fields, 'id' ) ); |
|
| 255 | + $fields[ $index ][ 'attributes' ][ 'data-depends' ] = $value; |
|
| 256 | + if( !$this->getValue( $fields[ $dependency ][ 'slug' ], $metabox[ 'slug' ] ) ) { |
|
| 257 | + $fields[ $index ][ 'class' ] = trim( 'hidden ' . $fields[ $index ][ 'class' ] ); |
|
| 258 | 258 | } |
| 259 | 259 | }); |
| 260 | 260 | return $metabox; |
@@ -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 | /** |