Passed
Push — master ( aebf2b...336c10 )
by Paul
02:23
created
src/MetaBox.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -26,8 +26,8 @@  discard block
 block discarded – undo
26 26
 	{
27 27
 		$this->normalize();
28 28
 
29
-		add_filter( 'rwmb_show',       [$this, 'isVisible'], 10, 2 );
30
-		add_action( 'rwmb_meta_boxes', [$this, 'register'] );
29
+		add_filter( 'rwmb_show', [ $this, 'isVisible' ], 10, 2 );
30
+		add_action( 'rwmb_meta_boxes', [ $this, 'register' ] );
31 31
 	}
32 32
 
33 33
 	/**
@@ -36,19 +36,19 @@  discard block
 block discarded – undo
36 36
 	public function isVisible( $bool, array $metabox )
37 37
 	{
38 38
 		if( defined( 'DOING_AJAX' )
39
-			|| !isset( $metabox['condition'] )
40
-			|| !$this->hasPostType( $metabox )) {
39
+			|| !isset( $metabox[ 'condition' ] )
40
+			|| !$this->hasPostType( $metabox ) ) {
41 41
 			return $bool;
42 42
 		}
43
-		return $this->verifyMetaBoxCondition( $metabox['condition'] );
43
+		return $this->verifyMetaBoxCondition( $metabox[ 'condition' ] );
44 44
 	}
45 45
 
46 46
 	/**
47 47
 	 * @return array
48 48
 	 */
49
-	public function register( $metaboxes = [] )
49
+	public function register( $metaboxes = [ ] )
50 50
 	{
51
-		if( current_user_can( 'switch_themes' )) {
51
+		if( current_user_can( 'switch_themes' ) ) {
52 52
 			$this->addInstructions();
53 53
 		}
54 54
 		return array_merge( $metaboxes, $this->metaboxes );
@@ -72,18 +72,18 @@  discard block
 block discarded – undo
72 72
 	{
73 73
 		if( !count( array_filter( $this->metaboxes, function( $metabox ) {
74 74
 			return $this->isVisible( false, $metabox );
75
-		})))return;
76
-		$this->metaboxes[] = [
75
+		}) ) )return;
76
+		$this->metaboxes[ ] = [
77 77
 			'id' => 'infodiv',
78 78
 			'post_types' => $this->getPostTypes(),
79 79
 			'title' => __( 'How to use in your theme', 'pollux' ),
80 80
 			'context' => 'side',
81 81
 			'priority' => 'low',
82
-			'fields' => [[
82
+			'fields' => [ [
83 83
 				'slug' => '',
84 84
 				'std' => $this->generateInstructions(),
85 85
 				'type' => 'custom_html',
86
-			]],
86
+			] ],
87 87
 		];
88 88
 	}
89 89
 
@@ -93,12 +93,12 @@  discard block
 block discarded – undo
93 93
 	protected function generateInstructions()
94 94
 	{
95 95
 		return array_reduce( $this->getInstructions(), function( $html, $metabox ) {
96
-			$fields = array_reduce( array_column( $metabox['fields'], 'slug' ), function( $html, $slug ) use( $metabox ) {
96
+			$fields = array_reduce( array_column( $metabox[ 'fields' ], 'slug' ), function( $html, $slug ) use( $metabox ) {
97 97
 				$hook = sprintf( 'pollux/%s/instruction', $this->getClassname() );
98
-				return $html . apply_filters( $hook, "PostMeta::get('{$slug}');", $slug, $metabox['slug'] ) . PHP_EOL;
98
+				return $html . apply_filters( $hook, "PostMeta::get('{$slug}');", $slug, $metabox[ 'slug' ] ) . PHP_EOL;
99 99
 			});
100 100
 			return $html . sprintf( '<p><strong>%s</strong></p><pre class="my-sites nav-tab-active misc-pub-section">%s</pre>',
101
-				$metabox['title'],
101
+				$metabox[ 'title' ],
102 102
 				$fields
103 103
 			);
104 104
 		});
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	protected function getInstructions()
111 111
 	{
112 112
 		return array_filter( $this->metaboxes, function( $metabox ) {
113
-			return $this->verifyMetaBoxCondition( $metabox['condition'] )
113
+			return $this->verifyMetaBoxCondition( $metabox[ 'condition' ] )
114 114
 				&& $this->hasPostType( $metabox );
115 115
 		});
116 116
 	}
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 	 */
121 121
 	protected function getPostId()
122 122
 	{
123
-		if( !( $postId = filter_input( INPUT_GET, 'post' ))) {
123
+		if( !( $postId = filter_input( INPUT_GET, 'post' ) ) ) {
124 124
 			$postId = filter_input( INPUT_POST, 'post_ID' );
125 125
 		}
126 126
 		return intval( $postId );
@@ -133,10 +133,10 @@  discard block
 block discarded – undo
133 133
 	{
134 134
 		return array_unique( iterator_to_array(
135 135
 			new RecursiveIteratorIterator(
136
-				new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' ))
136
+				new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' ) )
137 137
 			),
138 138
 			false
139
-		));
139
+		) );
140 140
 	}
141 141
 
142 142
 	/**
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
 	 */
145 145
 	protected function hasPostType( array $metabox )
146 146
 	{
147
-		if( !isset( $metabox['post_types'] )) {
147
+		if( !isset( $metabox[ 'post_types' ] ) ) {
148 148
 			return true;
149 149
 		}
150
-		return in_array( get_post_type( $this->getPostId() ), $metabox['post_types'] );
150
+		return in_array( get_post_type( $this->getPostId() ), $metabox[ 'post_types' ] );
151 151
 	}
152 152
 
153 153
 	/**
@@ -155,16 +155,16 @@  discard block
 block discarded – undo
155 155
 	 */
156 156
 	protected function normalize()
157 157
 	{
158
-		$this->metaboxes = [];
159
-		foreach( $this->app->config['meta_boxes'] as $id => $metabox ) {
158
+		$this->metaboxes = [ ];
159
+		foreach( $this->app->config[ 'meta_boxes' ] as $id => $metabox ) {
160 160
 			$defaults = [
161
-				'condition' => [],
162
-				'fields' => [],
161
+				'condition' => [ ],
162
+				'fields' => [ ],
163 163
 				'id' => $id,
164
-				'post_types' => [],
164
+				'post_types' => [ ],
165 165
 				'slug' => $id,
166 166
 			];
167
-			$this->metaboxes[] = $this->normalizeThis( $metabox, $defaults, $id );
167
+			$this->metaboxes[ ] = $this->normalizeThis( $metabox, $defaults, $id );
168 168
 		}
169 169
 	}
170 170
 
@@ -175,9 +175,9 @@  discard block
 block discarded – undo
175 175
 	protected function normalizeCondition( $conditions )
176 176
 	{
177 177
 		$conditions = $this->toArray( $conditions );
178
-		if( count( array_filter( array_keys( $conditions ), 'is_string' )) == 0 ) {
178
+		if( count( array_filter( array_keys( $conditions ), 'is_string' ) ) == 0 ) {
179 179
 			foreach( $conditions as $key ) {
180
-				$conditions[str_replace( '!', '', $key )] = substr( $key, 0, 1 ) == '!' ? 0 : 1;
180
+				$conditions[ str_replace( '!', '', $key ) ] = substr( $key, 0, 1 ) == '!' ? 0 : 1;
181 181
 			}
182 182
 			$conditions = array_filter( $conditions, function( $key ) {
183 183
 				return !is_numeric( $key );
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 		$hook = sprintf( 'pollux/%s/conditions', $this->getClassname() );
187 187
 		return array_intersect_key(
188 188
 			$conditions,
189
-			array_flip( apply_filters( $hook, static::CONDITIONS ))
189
+			array_flip( apply_filters( $hook, static::CONDITIONS ) )
190 190
 		);
191 191
 	}
192 192
 
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 	protected function normalizeFields( array $fields, array $data, $parentId )
197 197
 	{
198 198
 		return array_map( function( $id, $field ) use( $parentId ) {
199
-			$defaults =  [
199
+			$defaults = [
200 200
 				'id' => $id,
201 201
 				'field_name' => '',
202 202
 				'slug' => $id,
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 	 */
242 242
 	protected function validateIsFrontPage( $value )
243 243
 	{
244
-		return $value == ( $this->getPostId() == get_option( 'page_on_front' ));
244
+		return $value == ( $this->getPostId() == get_option( 'page_on_front' ) );
245 245
 	}
246 246
 
247 247
 	/**
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 	 */
251 251
 	protected function validateIsHome( $value )
252 252
 	{
253
-		return $value == ( $this->getPostId() == get_option( 'page_for_posts' ));
253
+		return $value == ( $this->getPostId() == get_option( 'page_for_posts' ) );
254 254
 	}
255 255
 
256 256
 	/**
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	 */
260 260
 	protected function validateIsPageTemplate( $value )
261 261
 	{
262
-		return basename( get_page_template_slug( $this->getPostId() )) == $value;
262
+		return basename( get_page_template_slug( $this->getPostId() ) ) == $value;
263 263
 	}
264 264
 
265 265
 	/**
Please login to merge, or discard this patch.
src/Settings.php 2 patches
Spacing   +31 added lines, -31 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,12 +173,12 @@  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
 			delete_option( static::ID );
178 178
 			// @todo: now trigger save to restore defaults
179 179
 			return add_settings_error( static::ID, 'reset', __( 'Settings reset to defaults.', 'pollux' ), 'updated' );
180 180
 		}
181
-		add_settings_error( static::ID, 'reset', __( 'Failed to reset settings. Please refresh the page and try again.', 'pollux' ));
181
+		add_settings_error( static::ID, 'reset', __( 'Failed to reset settings. Please refresh the page and try again.', 'pollux' ) );
182 182
 	}
183 183
 
184 184
 	/**
@@ -186,15 +186,15 @@  discard block
 block discarded – undo
186 186
 	 */
187 187
 	protected function normalize()
188 188
 	{
189
-		$this->metaboxes = [];
190
-		foreach( $this->app->config['settings'] as $id => $metabox ) {
189
+		$this->metaboxes = [ ];
190
+		foreach( $this->app->config[ 'settings' ] as $id => $metabox ) {
191 191
 			$defaults = [
192
-				'condition' => [],
193
-				'fields' => [],
192
+				'condition' => [ ],
193
+				'fields' => [ ],
194 194
 				'id' => $id,
195 195
 				'slug' => $id,
196 196
 			];
197
-			$this->metaboxes[] = $this->normalizeThis( $metabox, $defaults, $id );
197
+			$this->metaboxes[ ] = $this->normalizeThis( $metabox, $defaults, $id );
198 198
 		}
199 199
 	}
200 200
 
@@ -205,10 +205,10 @@  discard block
 block discarded – undo
205 205
 	 */
206 206
 	protected function normalizeFieldName( $name, array $data, $parentId )
207 207
 	{
208
-		if( !empty( $name )) {
208
+		if( !empty( $name ) ) {
209 209
 			return $name;
210 210
 		}
211
-		$name = str_replace( sprintf( '%s-%s-', static::ID, $parentId ), '', $data['id'] );
211
+		$name = str_replace( sprintf( '%s-%s-', static::ID, $parentId ), '', $data[ 'id' ] );
212 212
 		return sprintf( '%s[%s][%s]', static::ID, $parentId, $name );
213 213
 	}
214 214
 
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 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
 			delete_option( static::ID );
178 184
 			// @todo: now trigger save to restore defaults
Please login to merge, or discard this patch.