@@ -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( 'wp_redirect', [$this, 'filterRedirectOnSave'] ); |
|
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( 'wp_redirect', [ $this, 'filterRedirectOnSave' ] ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | public function action() |
63 | 63 | { |
64 | 64 | $args = func_get_args(); |
65 | - $hook = sprintf( 'pollux/%s/%s', static::ID, array_shift( $args )); |
|
66 | - return do_action_ref_array( $hook, array_filter( $args )); |
|
65 | + $hook = sprintf( 'pollux/%s/%s', static::ID, array_shift( $args ) ); |
|
66 | + return do_action_ref_array( $hook, array_filter( $args ) ); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | __( 'Site Settings', 'pollux' ), |
78 | 78 | 'edit_theme_options', |
79 | 79 | static::id(), |
80 | - [$this, 'renderPage'], |
|
80 | + [ $this, 'renderPage' ], |
|
81 | 81 | 'dashicons-screenoptions', |
82 | 82 | 1313 |
83 | - ])); |
|
83 | + ] ) ); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | call_user_func_array( 'add_meta_box', $this->filter( 'metabox/submit', [ |
93 | 93 | 'submitdiv', |
94 | 94 | __( 'Save Settings', 'pollux' ), |
95 | - [$this, 'renderSubmitMetaBox'], |
|
95 | + [ $this, 'renderSubmitMetaBox' ], |
|
96 | 96 | $this->hook, |
97 | 97 | 'side', |
98 | 98 | 'high', |
99 | - ])); |
|
99 | + ] ) ); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | public function filter() |
106 | 106 | { |
107 | 107 | $args = func_get_args(); |
108 | - $hook = sprintf( 'pollux/%s/%s', static::ID, array_shift( $args )); |
|
109 | - return apply_filters_ref_array( $hook, array_filter( $args )); |
|
108 | + $hook = sprintf( 'pollux/%s/%s', static::ID, array_shift( $args ) ); |
|
109 | + return apply_filters_ref_array( $hook, array_filter( $args ) ); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -129,13 +129,13 @@ discard block |
||
129 | 129 | public function filterRedirectOnSave( $location ) |
130 | 130 | { |
131 | 131 | if( strpos( $location, 'settings-updated=true' ) === false |
132 | - || strpos( $location, sprintf( 'page=%s', static::id() )) === false ) { |
|
132 | + || strpos( $location, sprintf( 'page=%s', static::id() ) ) === false ) { |
|
133 | 133 | return $location; |
134 | 134 | } |
135 | - return add_query_arg([ |
|
135 | + return add_query_arg( [ |
|
136 | 136 | 'page' => static::id(), |
137 | 137 | 'settings-updated' => 'true', |
138 | - ], admin_url( 'admin.php' )); |
|
138 | + ], admin_url( 'admin.php' ) ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | */ |
146 | 146 | public function filterSavedSettings( $settings ) |
147 | 147 | { |
148 | - if( is_null( $settings )) { |
|
149 | - $settings = []; |
|
148 | + if( is_null( $settings ) ) { |
|
149 | + $settings = [ ]; |
|
150 | 150 | } |
151 | 151 | $this->action( 'saved' ); |
152 | 152 | return $this->filter( 'save', $settings ); |
@@ -158,14 +158,14 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function register() |
160 | 160 | { |
161 | - if(( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
161 | + if( ( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
162 | 162 | foreach( parent::register() as $metabox ) { |
163 | 163 | new RWMetaBox( $metabox ); |
164 | 164 | } |
165 | 165 | add_screen_option( 'layout_columns', [ |
166 | 166 | 'max' => 2, |
167 | 167 | 'default' => 2, |
168 | - ]); |
|
168 | + ] ); |
|
169 | 169 | $this->action( 'init' ); |
170 | 170 | } |
171 | 171 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | */ |
176 | 176 | public function registerSetting() |
177 | 177 | { |
178 | - register_setting( static::id(), static::id(), [$this, 'filterSavedSettings'] ); |
|
178 | + register_setting( static::id(), static::id(), [ $this, 'filterSavedSettings' ] ); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -184,12 +184,12 @@ discard block |
||
184 | 184 | */ |
185 | 185 | public function renderFooterScript() |
186 | 186 | { |
187 | - if(( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
187 | + if( ( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
188 | 188 | $this->render( 'settings/script', [ |
189 | 189 | 'confirm' => __( 'Are you sure want to do this?', 'pollux' ), |
190 | 190 | 'hook' => $this->hook, |
191 | 191 | 'id' => static::id(), |
192 | - ]); |
|
192 | + ] ); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | 'columns' => get_current_screen()->get_columns(), |
203 | 203 | 'heading' => __( 'Site Settings', 'pollux' ), |
204 | 204 | 'id' => static::id(), |
205 | - ]); |
|
205 | + ] ); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -218,9 +218,9 @@ discard block |
||
218 | 218 | ]; |
219 | 219 | $this->render( 'settings/submit', [ |
220 | 220 | 'reset' => __( 'Reset', 'pollux' ), |
221 | - 'reset_url' => esc_url( add_query_arg( $query, admin_url( 'admin.php' ))), |
|
221 | + 'reset_url' => esc_url( add_query_arg( $query, admin_url( 'admin.php' ) ) ), |
|
222 | 222 | 'submit' => get_submit_button( __( 'Save', 'pollux' ), 'primary', 'submit', false ), |
223 | - ]); |
|
223 | + ] ); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -232,11 +232,11 @@ discard block |
||
232 | 232 | if( filter_input( INPUT_GET, 'page' ) !== static::id() |
233 | 233 | || filter_input( INPUT_GET, 'action' ) !== 'reset' |
234 | 234 | )return; |
235 | - if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook )) { |
|
235 | + if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook ) ) { |
|
236 | 236 | update_option( static::id(), $this->getDefaults() ); |
237 | 237 | return add_settings_error( static::id(), 'reset', __( 'All values have been reset to defaults.', 'pollux' ), 'updated' ); |
238 | 238 | } |
239 | - add_settings_error( static::id(), 'reset', __( 'Failed to reset values. Please refresh the page and try again.', 'pollux' )); |
|
239 | + add_settings_error( static::id(), 'reset', __( 'Failed to reset values. Please refresh the page and try again.', 'pollux' ) ); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | protected function filterArrayByKey( array $array, $key ) |
247 | 247 | { |
248 | 248 | return array_filter( $array, function( $value ) use( $key ) { |
249 | - return !empty( $value[$key] ); |
|
249 | + return !empty( $value[ $key ] ); |
|
250 | 250 | }); |
251 | 251 | } |
252 | 252 | |
@@ -259,11 +259,11 @@ discard block |
||
259 | 259 | |
260 | 260 | array_walk( $metaboxes, function( &$metabox ) { |
261 | 261 | $fields = array_map( function( $field ) { |
262 | - $field = wp_parse_args( $field, ['std' => ''] ); |
|
263 | - return [$field['slug'] => $field['std']]; |
|
264 | - }, $this->filterArrayByKey( $metabox['fields'], 'slug' )); |
|
262 | + $field = wp_parse_args( $field, [ 'std' => '' ] ); |
|
263 | + return [ $field[ 'slug' ] => $field[ 'std' ] ]; |
|
264 | + }, $this->filterArrayByKey( $metabox[ 'fields' ], 'slug' ) ); |
|
265 | 265 | $metabox = [ |
266 | - $metabox['slug'] => call_user_func_array( 'array_merge', $fields ), |
|
266 | + $metabox[ 'slug' ] => call_user_func_array( 'array_merge', $fields ), |
|
267 | 267 | ]; |
268 | 268 | }); |
269 | 269 | return call_user_func_array( 'array_merge', $metaboxes ); |
@@ -284,10 +284,10 @@ discard block |
||
284 | 284 | */ |
285 | 285 | protected function normalizeFieldName( $name, array $data, $parentId ) |
286 | 286 | { |
287 | - if( !empty( $name )) { |
|
287 | + if( !empty( $name ) ) { |
|
288 | 288 | return $name; |
289 | 289 | } |
290 | - $name = str_replace( sprintf( '%s-%s-', static::id(), $parentId ), '', $data['id'] ); |
|
290 | + $name = str_replace( sprintf( '%s-%s-', static::id(), $parentId ), '', $data[ 'id' ] ); |
|
291 | 291 | return sprintf( '%s[%s][%s]', static::id(), $parentId, $name ); |
292 | 292 | } |
293 | 293 |
@@ -158,7 +158,9 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function register() |
160 | 160 | { |
161 | - if(( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
161 | + if(( new Helper )->getCurrentScreen()->id != $this->hook ) { |
|
162 | + return; |
|
163 | + } |
|
162 | 164 | foreach( parent::register() as $metabox ) { |
163 | 165 | new RWMetaBox( $metabox ); |
164 | 166 | } |
@@ -184,7 +186,9 @@ discard block |
||
184 | 186 | */ |
185 | 187 | public function renderFooterScript() |
186 | 188 | { |
187 | - if(( new Helper )->getCurrentScreen()->id != $this->hook )return; |
|
189 | + if(( new Helper )->getCurrentScreen()->id != $this->hook ) { |
|
190 | + return; |
|
191 | + } |
|
188 | 192 | $this->render( 'settings/script', [ |
189 | 193 | 'confirm' => __( 'Are you sure want to do this?', 'pollux' ), |
190 | 194 | 'hook' => $this->hook, |
@@ -231,7 +235,9 @@ discard block |
||
231 | 235 | { |
232 | 236 | if( filter_input( INPUT_GET, 'page' ) !== static::id() |
233 | 237 | || filter_input( INPUT_GET, 'action' ) !== 'reset' |
234 | - )return; |
|
238 | + ) { |
|
239 | + return; |
|
240 | + } |
|
235 | 241 | if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook )) { |
236 | 242 | update_option( static::id(), $this->getDefaults() ); |
237 | 243 | return add_settings_error( static::id(), 'reset', __( 'All values have been reset to defaults.', 'pollux' ), 'updated' ); |
@@ -245,7 +251,8 @@ discard block |
||
245 | 251 | */ |
246 | 252 | protected function filterArrayByKey( array $array, $key ) |
247 | 253 | { |
248 | - return array_filter( $array, function( $value ) use( $key ) { |
|
254 | + return array_filter( $array, function( $value ) use( $key ) |
|
255 | + { |
|
249 | 256 | return !empty( $value[$key] ); |
250 | 257 | }); |
251 | 258 | } |
@@ -257,8 +264,10 @@ discard block |
||
257 | 264 | { |
258 | 265 | $metaboxes = $this->filterArrayByKey( $this->metaboxes, 'slug' ); |
259 | 266 | |
260 | - array_walk( $metaboxes, function( &$metabox ) { |
|
261 | - $fields = array_map( function( $field ) { |
|
267 | + array_walk( $metaboxes, function( &$metabox ) |
|
268 | + { |
|
269 | + $fields = array_map( function( $field ) |
|
270 | + { |
|
262 | 271 | $field = wp_parse_args( $field, ['std' => ''] ); |
263 | 272 | return [$field['slug'] => $field['std']]; |
264 | 273 | }, $this->filterArrayByKey( $metabox['fields'], 'slug' )); |
@@ -15,10 +15,10 @@ discard block |
||
15 | 15 | public function get( $group = null, $key = null, $fallback = null ) |
16 | 16 | { |
17 | 17 | $options = $this->getOption(); |
18 | - if( empty( $options )) { |
|
18 | + if( empty( $options ) ) { |
|
19 | 19 | return $fallback; |
20 | 20 | } |
21 | - if( !is_string( $group )) { |
|
21 | + if( !is_string( $group ) ) { |
|
22 | 22 | return $options; |
23 | 23 | } |
24 | 24 | $group = $this->normalize( $options, $group, $fallback ); |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | */ |
33 | 33 | protected function getOption() |
34 | 34 | { |
35 | - return get_option( Settings::id(), [] ); |
|
35 | + return get_option( Settings::id(), [ ] ); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | */ |
43 | 43 | protected function normalize( array $options, $key, $fallback ) |
44 | 44 | { |
45 | - if( !array_key_exists( $key, $options )) { |
|
45 | + if( !array_key_exists( $key, $options ) ) { |
|
46 | 46 | return $fallback; |
47 | 47 | } |
48 | - $option = $options[$key]; |
|
48 | + $option = $options[ $key ]; |
|
49 | 49 | $option = is_array( $option ) |
50 | 50 | ? array_filter( $option ) |
51 | 51 | : trim( $option ); |
@@ -12,6 +12,6 @@ |
||
12 | 12 | */ |
13 | 13 | protected function getOption() |
14 | 14 | { |
15 | - return get_option( apply_filters( 'pollux/archives/option', Archive::ID ), [] ); |
|
15 | + return get_option( apply_filters( 'pollux/archives/option', Archive::ID ), [ ] ); |
|
16 | 16 | } |
17 | 17 | } |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | { |
22 | 22 | parent::init(); |
23 | 23 | |
24 | - add_action( 'pollux/archives/saved', [$this, 'addCustomNoticeOnSave'] ); |
|
25 | - add_action( 'pollux/archives/editor', [$this, 'renderEditor'] ); |
|
26 | - add_filter( 'pollux/archives/metabox/submit', [$this, 'filterSubmitMetaBox'] ); |
|
24 | + add_action( 'pollux/archives/saved', [ $this, 'addCustomNoticeOnSave' ] ); |
|
25 | + add_action( 'pollux/archives/editor', [ $this, 'renderEditor' ] ); |
|
26 | + add_filter( 'pollux/archives/metabox/submit', [ $this, 'filterSubmitMetaBox' ] ); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | __( 'Archive', 'pollux' ), |
50 | 50 | 'edit_theme_options', |
51 | 51 | static::id(), |
52 | - [$this, 'renderPage'], |
|
53 | - ])); |
|
52 | + [ $this, 'renderPage' ], |
|
53 | + ] ) ); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function filterSubmitMetaBox( array $args ) |
73 | 73 | { |
74 | - $args[1] = __( 'Save Archive', 'pollux' ); |
|
74 | + $args[ 1 ] = __( 'Save Archive', 'pollux' ); |
|
75 | 75 | return $args; |
76 | 76 | } |
77 | 77 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | 'wp_autoresize_on' => true, |
92 | 92 | 'add_unload_trigger' => false, |
93 | 93 | ], |
94 | - ]); |
|
94 | + ] ); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | 'heading' => sprintf( __( '%s Archive', 'pollux' ), 'Post' ), |
107 | 107 | 'id' => static::id(), |
108 | 108 | 'title' => ArchiveMeta::get( 'title' ), |
109 | - ]); |
|
109 | + ] ); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | */ |
115 | 115 | protected function getDefaults() |
116 | 116 | { |
117 | - return []; |
|
117 | + return [ ]; |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -12,7 +12,7 @@ |
||
12 | 12 | /** |
13 | 13 | * @var string |
14 | 14 | */ |
15 | - CONST ID = 'archives'; |
|
15 | + const ID = 'archives'; |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * {@inheritdoc} |