Passed
Push — master ( 336c10...5d2e19 )
by Paul
02:17
created
src/Settings.php 2 patches
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -28,18 +28,18 @@  discard block
 block discarded – undo
28 28
 	public function init()
29 29
 	{
30 30
 		// @todo: run GateKeeper here instead to check dependencies and capability
31
-		if( !is_plugin_active( 'meta-box/meta-box.php' ))return;
31
+		if( !is_plugin_active( 'meta-box/meta-box.php' ) )return;
32 32
 
33 33
 		$this->normalize();
34 34
 
35
-		add_action( 'admin_menu',                               [$this, 'addPage'] );
36
-		add_action( 'pollux/settings/init',                     [$this, 'addSubmitMetaBox'] );
37
-		add_filter( 'pollux/settings/instruction',              [$this, 'filterInstruction'], 10, 3 );
38
-		add_filter( 'wp_redirect',                              [$this, 'filterRedirectOnSave'] );
39
-		add_action( 'current_screen',                           [$this, 'register'] );
40
-		add_action( 'admin_menu',                               [$this, 'registerSetting'] );
41
-		add_action( 'pollux/settings/init',                     [$this, 'reset'] );
42
-		add_action( 'admin_footer-toplevel_page_' . static::ID, [$this, 'renderFooterScript'] );
35
+		add_action( 'admin_menu', [ $this, 'addPage' ] );
36
+		add_action( 'pollux/settings/init', [ $this, 'addSubmitMetaBox' ] );
37
+		add_filter( 'pollux/settings/instruction', [ $this, 'filterInstruction' ], 10, 3 );
38
+		add_filter( 'wp_redirect', [ $this, 'filterRedirectOnSave' ] );
39
+		add_action( 'current_screen', [ $this, 'register' ] );
40
+		add_action( 'admin_menu', [ $this, 'registerSetting' ] );
41
+		add_action( 'pollux/settings/init', [ $this, 'reset' ] );
42
+		add_action( 'admin_footer-toplevel_page_' . static::ID, [ $this, 'renderFooterScript' ] );
43 43
 	}
44 44
 
45 45
 	/**
@@ -52,10 +52,10 @@  discard block
 block discarded – undo
52 52
 			__( 'Site Settings', 'pollux' ),
53 53
 			'edit_theme_options',
54 54
 			static::ID,
55
-			[$this, 'renderPage'],
55
+			[ $this, 'renderPage' ],
56 56
 			'dashicons-screenoptions',
57 57
 			1313
58
-		]));
58
+		] ) );
59 59
 	}
60 60
 
61 61
 	/**
@@ -66,11 +66,11 @@  discard block
 block discarded – undo
66 66
 		call_user_func_array( 'add_meta_box', apply_filters( 'pollux/settings/metabox/submit', [
67 67
 			'submitdiv',
68 68
 			__( 'Save Settings', 'pollux' ),
69
-			[ $this, 'renderSubmitMetaBox'],
69
+			[ $this, 'renderSubmitMetaBox' ],
70 70
 			$this->hook,
71 71
 			'side',
72 72
 			'high',
73
-		]));
73
+		] ) );
74 74
 	}
75 75
 
76 76
 	/**
@@ -91,19 +91,19 @@  discard block
 block discarded – undo
91 91
 	public function filterRedirectOnSave( $location )
92 92
 	{
93 93
 		if( strpos( $location, 'settings-updated=true' ) === false
94
-			|| strpos( $location, sprintf( 'page=%s', static::ID )) === false ) {
94
+			|| strpos( $location, sprintf( 'page=%s', static::ID ) ) === false ) {
95 95
 			return $location;
96 96
 		}
97
-		return add_query_arg([
97
+		return add_query_arg( [
98 98
 			'page' => static::ID,
99 99
 			'settings-updated' => 'true',
100
-		], admin_url( 'admin.php' ));
100
+		], admin_url( 'admin.php' ) );
101 101
 	}
102 102
 
103 103
 	/**
104 104
 	 * @return void
105 105
 	 */
106
-	public function register( $metaboxes = [] )
106
+	public function register( $metaboxes = [ ] )
107 107
 	{
108 108
 		if( get_current_screen()->id != $this->hook )return;
109 109
 		foreach( parent::register() as $metabox ) {
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 		add_screen_option( 'layout_columns', [
113 113
 			'max' => 2,
114 114
 			'default' => 2,
115
-		]);
115
+		] );
116 116
 		do_action( 'pollux/settings/init' );
117 117
 	}
118 118
 
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 			'confirm' => __( 'Are you sure want to do this?', 'pollux' ),
134 134
 			'hook' => $this->hook,
135 135
 			'id' => static::ID,
136
-		]);
136
+		] );
137 137
 	}
138 138
 
139 139
 	/**
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 			'columns' => get_current_screen()->get_columns(),
146 146
 			'id' => static::ID,
147 147
 			'title' => __( 'Site Settings', 'pollux' ),
148
-		]);
148
+		] );
149 149
 	}
150 150
 
151 151
 	/**
@@ -160,9 +160,9 @@  discard block
 block discarded – undo
160 160
 		];
161 161
 		$this->render( 'settings/submit', [
162 162
 			'reset' => __( 'Reset Settings', 'pollux' ),
163
-			'reset_url' => esc_url( add_query_arg( $query, admin_url( 'admin.php' ))),
163
+			'reset_url' => esc_url( add_query_arg( $query, admin_url( 'admin.php' ) ) ),
164 164
 			'submit' => get_submit_button( __( 'Save', 'pollux' ), 'primary', 'submit', false ),
165
-		]);
165
+		] );
166 166
 	}
167 167
 
168 168
 	/**
@@ -173,11 +173,11 @@  discard block
 block discarded – undo
173 173
 		if( filter_input( INPUT_GET, 'page' ) !== static::ID
174 174
 			|| filter_input( INPUT_GET, 'action' ) !== 'reset'
175 175
 		)return;
176
-		if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook )) {
176
+		if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook ) ) {
177 177
 			update_option( static::ID, $this->getDefaults() );
178 178
 			return add_settings_error( static::ID, 'reset', __( 'Settings reset to defaults.', 'pollux' ), 'updated' );
179 179
 		}
180
-		add_settings_error( static::ID, 'reset', __( 'Failed to reset settings. Please refresh the page and try again.', 'pollux' ));
180
+		add_settings_error( static::ID, 'reset', __( 'Failed to reset settings. Please refresh the page and try again.', 'pollux' ) );
181 181
 	}
182 182
 
183 183
 	/**
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	protected function filterArrayByKey( array $array, $key )
188 188
 	{
189 189
 		return array_filter( $array, function( $value ) use( $key ) {
190
-			return !empty( $value[$key] );
190
+			return !empty( $value[ $key ] );
191 191
 		});
192 192
 	}
193 193
 
@@ -200,11 +200,11 @@  discard block
 block discarded – undo
200 200
 
201 201
 		array_walk( $metaboxes, function( &$metabox ) {
202 202
 			$fields = array_map( function( $field ) {
203
-				$field = wp_parse_args( $field, ['std' => ''] );
204
-				return [$field['slug'] => $field['std']];
205
-			}, $this->filterArrayByKey( $metabox['fields'], 'slug' ));
203
+				$field = wp_parse_args( $field, [ 'std' => '' ] );
204
+				return [ $field[ 'slug' ] => $field[ 'std' ] ];
205
+			}, $this->filterArrayByKey( $metabox[ 'fields' ], 'slug' ) );
206 206
 			$metabox = [
207
-				$metabox['slug'] => call_user_func_array( 'array_merge', $fields ),
207
+				$metabox[ 'slug' ] => call_user_func_array( 'array_merge', $fields ),
208 208
 			];
209 209
 		});
210 210
 		return call_user_func_array( 'array_merge', $metaboxes );
@@ -215,15 +215,15 @@  discard block
 block discarded – undo
215 215
 	 */
216 216
 	protected function normalize()
217 217
 	{
218
-		$this->metaboxes = [];
219
-		foreach( $this->app->config['settings'] as $id => $metabox ) {
218
+		$this->metaboxes = [ ];
219
+		foreach( $this->app->config[ 'settings' ] as $id => $metabox ) {
220 220
 			$defaults = [
221
-				'condition' => [],
222
-				'fields' => [],
221
+				'condition' => [ ],
222
+				'fields' => [ ],
223 223
 				'id' => $id,
224 224
 				'slug' => $id,
225 225
 			];
226
-			$this->metaboxes[] = $this->normalizeThis( $metabox, $defaults, $id );
226
+			$this->metaboxes[ ] = $this->normalizeThis( $metabox, $defaults, $id );
227 227
 		}
228 228
 	}
229 229
 
@@ -234,10 +234,10 @@  discard block
 block discarded – undo
234 234
 	 */
235 235
 	protected function normalizeFieldName( $name, array $data, $parentId )
236 236
 	{
237
-		if( !empty( $name )) {
237
+		if( !empty( $name ) ) {
238 238
 			return $name;
239 239
 		}
240
-		$name = str_replace( sprintf( '%s-%s-', static::ID, $parentId ), '', $data['id'] );
240
+		$name = str_replace( sprintf( '%s-%s-', static::ID, $parentId ), '', $data[ 'id' ] );
241 241
 		return sprintf( '%s[%s][%s]', static::ID, $parentId, $name );
242 242
 	}
243 243
 
Please login to merge, or discard this patch.
Braces   +15 added lines, -6 removed lines patch added patch discarded remove patch
@@ -28,7 +28,9 @@  discard block
 block discarded – undo
28 28
 	public function init()
29 29
 	{
30 30
 		// @todo: run GateKeeper here instead to check dependencies and capability
31
-		if( !is_plugin_active( 'meta-box/meta-box.php' ))return;
31
+		if( !is_plugin_active( 'meta-box/meta-box.php' )) {
32
+			return;
33
+		}
32 34
 
33 35
 		$this->normalize();
34 36
 
@@ -105,7 +107,9 @@  discard block
 block discarded – undo
105 107
 	 */
106 108
 	public function register( $metaboxes = [] )
107 109
 	{
108
-		if( get_current_screen()->id != $this->hook )return;
110
+		if( get_current_screen()->id != $this->hook ) {
111
+			return;
112
+		}
109 113
 		foreach( parent::register() as $metabox ) {
110 114
 			new SettingsMetaBox( $metabox );
111 115
 		}
@@ -172,7 +176,9 @@  discard block
 block discarded – undo
172 176
 	{
173 177
 		if( filter_input( INPUT_GET, 'page' ) !== static::ID
174 178
 			|| filter_input( INPUT_GET, 'action' ) !== 'reset'
175
-		)return;
179
+		) {
180
+			return;
181
+		}
176 182
 		if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook )) {
177 183
 			update_option( static::ID, $this->getDefaults() );
178 184
 			return add_settings_error( static::ID, 'reset', __( 'Settings reset to defaults.', 'pollux' ), 'updated' );
@@ -186,7 +192,8 @@  discard block
 block discarded – undo
186 192
 	 */
187 193
 	protected function filterArrayByKey( array $array, $key )
188 194
 	{
189
-		return array_filter( $array, function( $value ) use( $key ) {
195
+		return array_filter( $array, function( $value ) use( $key )
196
+		{
190 197
 			return !empty( $value[$key] );
191 198
 		});
192 199
 	}
@@ -198,8 +205,10 @@  discard block
 block discarded – undo
198 205
 	{
199 206
 		$metaboxes = $this->filterArrayByKey( $this->metaboxes, 'slug' );
200 207
 
201
-		array_walk( $metaboxes, function( &$metabox ) {
202
-			$fields = array_map( function( $field ) {
208
+		array_walk( $metaboxes, function( &$metabox )
209
+		{
210
+			$fields = array_map( function( $field )
211
+			{
203 212
 				$field = wp_parse_args( $field, ['std' => ''] );
204 213
 				return [$field['slug'] => $field['std']];
205 214
 			}, $this->filterArrayByKey( $metabox['fields'], 'slug' ));
Please login to merge, or discard this patch.