Passed
Push — develop ( 83d763...37b65a )
by Paul
02:45
created
src/Settings/Settings.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -44,16 +44,16 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,7 +284,7 @@  discard block
 block discarded – undo
284 284
 	 */
285 285
 	protected function normalizeFieldName( $name, array $data, $parentId )
286 286
 	{
287
-		return sprintf( '%s[%s][%s]', static::id(), $parentId, $data['slug'] );
287
+		return sprintf( '%s[%s][%s]', static::id(), $parentId, $data[ 'slug' ] );
288 288
 	}
289 289
 
290 290
 	/**
Please login to merge, or discard this patch.