Passed
Push — master ( aaaeb8...fae2ce )
by Joseph
07:18 queued 10s
created
classes/subway-metabox.php 1 patch
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 namespace Subway;
24 24
 
25
-if ( ! defined( 'ABSPATH' ) ) {
25
+if ( ! defined('ABSPATH')) {
26 26
 	return;
27 27
 }
28 28
 
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
 	 */
56 56
 	public function __construct() {
57 57
 
58
-		add_action( 'add_meta_boxes', array( $this, 'addMetabox' ) );
59
-		add_action( 'save_post', array( $this, 'saveMetaboxValues' ) );
60
-		add_filter( 'the_content', array( $this, 'showContentToAllowedRoles' ) );
58
+		add_action('add_meta_boxes', array($this, 'addMetabox'));
59
+		add_action('save_post', array($this, 'saveMetaboxValues'));
60
+		add_filter('the_content', array($this, 'showContentToAllowedRoles'));
61 61
 
62 62
 		return $this;
63 63
 	}
@@ -85,11 +85,11 @@  discard block
 block discarded – undo
85 85
 
86 86
 		$post_types = $this->getPostTypes();
87 87
 
88
-		foreach ( $post_types as $post_type => $value ) {
88
+		foreach ($post_types as $post_type => $value) {
89 89
 			add_meta_box(
90 90
 				'subway_visibility_metabox',
91
-				esc_html__( 'Subway: Visibility Option', 'subway' ),
92
-				array( $this, 'visibilityMetabox' ),
91
+				esc_html__('Subway: Visibility Option', 'subway'),
92
+				array($this, 'visibilityMetabox'),
93 93
 				$post_type,
94 94
 				'side',
95 95
 				'high'
@@ -106,64 +106,64 @@  discard block
 block discarded – undo
106 106
 	 * @access public
107 107
 	 * @return void
108 108
 	 */
109
-	public function visibilityMetabox( $post ) {
109
+	public function visibilityMetabox($post) {
110 110
 
111 111
 		$howto = __(
112 112
 			'Choose the accessibility of this page from the options above.',
113 113
 			'subway'
114 114
 		);
115 115
 
116
-		$private_setting_label = __( 'Members Only', 'subway' );
116
+		$private_setting_label = __('Members Only', 'subway');
117 117
 
118
-		$is_post_private         = self::isPostPrivate( $post->ID );
118
+		$is_post_private = self::isPostPrivate($post->ID);
119 119
 
120 120
 		// Make sure the form request comes from WordPress
121
-		wp_nonce_field( basename( __FILE__ ),  'subway_post_visibility_nonce' );
121
+		wp_nonce_field(basename(__FILE__), 'subway_post_visibility_nonce');
122 122
 
123 123
 		// Disable the options (radio) when site is selected as public
124 124
 		?>
125 125
 		
126
-		<?php if ( ! Options::isPublicSite() ) :  ?>
126
+		<?php if ( ! Options::isPublicSite()) :  ?>
127 127
 		<?php // Site is private. Give them some Beer! ?>
128 128
 			<p>
129 129
 				<label class="subway-visibility-settings-checkbox-label" for="subway-visibility-public">
130
-					<input type="radio" class="subway-visibility-settings-radio" id="subway-visibility-public" name="subway-visibility-settings" value="public" <?php echo checked( false, $is_post_private, false ); ?>>
131
-					<?php esc_html_e( 'Public', 'subway' ) ?>
130
+					<input type="radio" class="subway-visibility-settings-radio" id="subway-visibility-public" name="subway-visibility-settings" value="public" <?php echo checked(false, $is_post_private, false); ?>>
131
+					<?php esc_html_e('Public', 'subway') ?>
132 132
 				</label>
133 133
 			</p>
134 134
 			<p>
135 135
 				<label class="subway-visibility-settings-checkbox-label" for="subway-visibility-private">
136 136
 					<input type="radio" class="subway-visibility-settings-radio" id="subway-visibility-private" name="subway-visibility-settings"
137
-					value="private" <?php echo checked( true, $is_post_private, false ); ?>>
138
-					<?php esc_html_e( 'Members Only', 'subway' ) ?>
137
+					value="private" <?php echo checked(true, $is_post_private, false); ?>>
138
+					<?php esc_html_e('Members Only', 'subway') ?>
139 139
 				 </label>
140 140
 			</p>
141 141
 			<div id="subway-roles-access-visibility-fields" class="hidden">
142 142
 				<dl>
143
-					<?php $post_allowed_user_roles = self::getAllowedUserRoles( $post->ID ); ?>
143
+					<?php $post_allowed_user_roles = self::getAllowedUserRoles($post->ID); ?>
144 144
 					<?php $editable_roles = get_editable_roles(); ?>
145 145
 					<?php // Remove administrator for editable roles. ?>
146
-					<?php unset( $editable_roles['administrator'] ); ?>
147
-					<?php foreach ( $editable_roles as $role_name => $role_info ) { ?>
146
+					<?php unset($editable_roles['administrator']); ?>
147
+					<?php foreach ($editable_roles as $role_name => $role_info) { ?>
148 148
 						<dt>
149
-							<?php $id = 'subway-visibility-settings-user-role-' . esc_html( $role_name ); ?>
150
-							<label for="<?php echo esc_attr( $id ); ?>">
151
-							<?php if ( is_array( $post_allowed_user_roles ) && in_array( $role_name, $post_allowed_user_roles ) ) { ?>
149
+							<?php $id = 'subway-visibility-settings-user-role-' . esc_html($role_name); ?>
150
+							<label for="<?php echo esc_attr($id); ?>">
151
+							<?php if (is_array($post_allowed_user_roles) && in_array($role_name, $post_allowed_user_roles)) { ?>
152 152
 								<?php $checked = 'checked'; ?>
153 153
 							<?php } else { ?>
154
-								<?php if ( false === $post_allowed_user_roles ) { ?>
154
+								<?php if (false === $post_allowed_user_roles) { ?>
155 155
 									<?php $checked = 'checked'; ?>
156 156
 								<?php } else { ?>
157 157
 										<?php $checked = ''; ?>
158 158
 								<?php } ?>
159 159
 							<?php } ?>
160
-							<input <?php echo esc_attr( $checked ); ?> id="<?php echo esc_attr( $id ); ?>" type="checkbox" 
161
-							name="subway-visibility-settings-user-role[]" class="subway-visibility-settings-role-access" value="<?php echo esc_attr( $role_name ); ?>" />
162
-								<?php echo esc_html( $role_info['name'] ); ?>
160
+							<input <?php echo esc_attr($checked); ?> id="<?php echo esc_attr($id); ?>" type="checkbox" 
161
+							name="subway-visibility-settings-user-role[]" class="subway-visibility-settings-role-access" value="<?php echo esc_attr($role_name); ?>" />
162
+								<?php echo esc_html($role_info['name']); ?>
163 163
 							</label>
164 164
 						</dt>
165 165
 					<?php } ?>
166
-					<p class="howto"><?php echo esc_html_e( 'Uncheck the user roles that you do not want to have access to this content','subway' ); ?></p>
166
+					<p class="howto"><?php echo esc_html_e('Uncheck the user roles that you do not want to have access to this content', 'subway'); ?></p>
167 167
 				</dl>
168 168
 			</div>
169 169
 			<script>
@@ -180,11 +180,11 @@  discard block
 block discarded – undo
180 180
 					});
181 181
 				});
182 182
 			</script>
183
-			<p class="howto"><?php echo esc_html( $howto ); ?></p>
183
+			<p class="howto"><?php echo esc_html($howto); ?></p>
184 184
 		<?php else : ?>
185 185
 			<?php // Site is public! Explain to them ?>
186 186
 			<p><em>
187
-				<?php esc_html_e( 'You have chosen to make your site public inside Settings > Subway. Make your site private so that you can select visibility options.', 'subway' ); ?>
187
+				<?php esc_html_e('You have chosen to make your site public inside Settings > Subway. Make your site private so that you can select visibility options.', 'subway'); ?>
188 188
 			</em>
189 189
 			</p>
190 190
 		<?php endif; ?>
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 	 * @access public
201 201
 	 * @return boolean false Returns false if nonce is not valid.
202 202
 	 */
203
-	public function saveVisibilityMetabox( $post_id = '' ) {
203
+	public function saveVisibilityMetabox($post_id = '') {
204 204
 
205 205
 		$public_posts     = Options::getPublicPostsIdentifiers();
206 206
 
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 		);
215 215
 
216 216
 		$post_visibility = filter_input(
217
-			INPUT_POST,  $visibility_field,
217
+			INPUT_POST, $visibility_field,
218 218
 			FILTER_SANITIZE_STRING
219 219
 		);
220 220
 
@@ -222,39 +222,39 @@  discard block
 block discarded – undo
222 222
 			$visibility_nonce
223 223
 		);
224 224
 
225
-		$allowed_roles = filter_input( INPUT_POST, 'subway-visibility-settings-user-role', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
225
+		$allowed_roles = filter_input(INPUT_POST, 'subway-visibility-settings-user-role', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
226 226
 
227 227
 		// verify taxonomies meta box nonce
228
-		if ( false === $is_valid_visibility_nonce ) {
228
+		if (false === $is_valid_visibility_nonce) {
229 229
 			return;
230 230
 		}
231
-		if ( empty( $allowed_roles ) ) {
231
+		if (empty($allowed_roles)) {
232 232
 			$allowed_roles = array();
233 233
 		}
234 234
 
235 235
 		// Update user roles.
236
-		update_post_meta( $post_id, 'subway-visibility-settings-allowed-user-roles', $allowed_roles );
236
+		update_post_meta($post_id, 'subway-visibility-settings-allowed-user-roles', $allowed_roles);
237 237
 
238
-		if ( ! empty( $post_visibility ) ) {
239
-			if ( ! empty( $post_id ) ) {
240
-				if ( 'public' === $post_visibility ) {
241
-					if ( ! in_array( $post_id, $public_posts ) ) {
242
-						array_push( $public_posts, $post_id );
238
+		if ( ! empty($post_visibility)) {
239
+			if ( ! empty($post_id)) {
240
+				if ('public' === $post_visibility) {
241
+					if ( ! in_array($post_id, $public_posts)) {
242
+						array_push($public_posts, $post_id);
243 243
 					}
244 244
 				}
245
-				if ( 'private' === $post_visibility ) {
246
-					unset( $public_posts[ array_search( $post_id, $public_posts ) ] );
245
+				if ('private' === $post_visibility) {
246
+					unset($public_posts[array_search($post_id, $public_posts)]);
247 247
 				}
248 248
 			}
249 249
 		}
250 250
 
251
-		if ( ! empty( $post_id ) ) {
252
-			$posts_implode = implode( ', ', $public_posts );
251
+		if ( ! empty($post_id)) {
252
+			$posts_implode = implode(', ', $public_posts);
253 253
 
254
-			if ( 'inherit' !== get_post_status( $post_id ) ) {
254
+			if ('inherit' !== get_post_status($post_id)) {
255 255
 
256
-				if ( true === $is_valid_visibility_nonce ) {
257
-					update_option( 'subway_public_post', $posts_implode );
256
+				if (true === $is_valid_visibility_nonce) {
257
+					update_option('subway_public_post', $posts_implode);
258 258
 					update_post_meta(
259 259
 						$post_id,
260 260
 						self::VISIBILITY_METAKEY,
@@ -274,9 +274,9 @@  discard block
 block discarded – undo
274 274
 	 * @access public
275 275
 	 * @return boolean false Returns false if nonce is not valid.
276 276
 	 */
277
-	public function saveMetaboxValues( $post_id ) {
277
+	public function saveMetaboxValues($post_id) {
278 278
 
279
-		$this->saveVisibilityMetabox( $post_id );
279
+		$this->saveVisibilityMetabox($post_id);
280 280
 		return;
281 281
 	}
282 282
 
@@ -290,16 +290,16 @@  discard block
 block discarded – undo
290 290
 	 * @access public
291 291
 	 * @return void
292 292
 	 */
293
-	public static function getPostTypes( $args = '', $output = '' ) {
293
+	public static function getPostTypes($args = '', $output = '') {
294 294
 
295
-		if ( empty( $args ) ) {
295
+		if (empty($args)) {
296 296
 			$args = array(
297 297
 			'public'   => true,
298 298
 			);
299 299
 			$output = 'names';
300 300
 		}
301 301
 
302
-		$post_types = get_post_types( $args, $output );
302
+		$post_types = get_post_types($args, $output);
303 303
 
304 304
 		return $post_types;
305 305
 	}
@@ -313,9 +313,9 @@  discard block
 block discarded – undo
313 313
 	 * @access public
314 314
 	 * @return boolean true Returns true if nonce is valid.
315 315
 	 */
316
-	public function isNonceValid( $nonce ) {
316
+	public function isNonceValid($nonce) {
317 317
 
318
-		if ( ! isset( $nonce ) || ! wp_verify_nonce( $nonce, basename( __FILE__ ) ) ) {
318
+		if ( ! isset($nonce) || ! wp_verify_nonce($nonce, basename(__FILE__))) {
319 319
 			return;
320 320
 		}
321 321
 
@@ -331,23 +331,23 @@  discard block
 block discarded – undo
331 331
 	 * @access public
332 332
 	 * @return boolean true Returns true if post is private. Otherwise false.
333 333
 	 */
334
-	public static function isPostPrivate( $post_id ) {
334
+	public static function isPostPrivate($post_id) {
335 335
 
336 336
 		$meta_value = '';
337 337
 
338
-		if ( ! empty( $post_id ) ) {
339
-			$meta_value = get_post_meta( $post_id, self::VISIBILITY_METAKEY, true );
338
+		if ( ! empty($post_id)) {
339
+			$meta_value = get_post_meta($post_id, self::VISIBILITY_METAKEY, true);
340 340
 
341 341
 			// New page or old pages that don't have Subway'\ Visibility Options
342
-			if ( empty( $meta_value ) ) {
342
+			if (empty($meta_value)) {
343 343
 				// Get the value from the general settings (Settings > Subway)
344 344
 				$is_site_public = Options::isPublicSite();
345
-				if ( ! $is_site_public ) {
345
+				if ( ! $is_site_public) {
346 346
 					// It's private.
347 347
 					return true;
348 348
 				}
349 349
 			}
350
-			if ( 'private' === $meta_value ) {
350
+			if ('private' === $meta_value) {
351 351
 				return true;
352 352
 			}
353 353
 		}
@@ -364,12 +364,12 @@  discard block
 block discarded – undo
364 364
 	 * @access public
365 365
 	 * @return boolean true Returns true if post is public. Otherwise false.
366 366
 	 */
367
-	public static function isPostPublic( $post_id ) {
367
+	public static function isPostPublic($post_id) {
368 368
 
369 369
 		$public_post = Options::getPublicPostsIdentifiers();
370 370
 
371
-		if ( ! empty( $post_id ) ) {
372
-			if ( ! in_array( $post_id, $public_post, true ) ) {
371
+		if ( ! empty($post_id)) {
372
+			if ( ! in_array($post_id, $public_post, true)) {
373 373
 				return true;
374 374
 			}
375 375
 		}
@@ -383,14 +383,14 @@  discard block
 block discarded – undo
383 383
 	 * @param  integer $post_id The post ID.
384 384
 	 * @return mixed Boolean false if metadata does not exists. Otherwise, return the array value of meta.
385 385
 	 */
386
-	public static function getAllowedUserRoles( $post_id = 0 ) {
386
+	public static function getAllowedUserRoles($post_id = 0) {
387 387
 
388 388
 		$allowed_roles = array();
389 389
 
390
-		if ( ! empty( $post_id ) ) {
391
-			if ( metadata_exists( 'post', $post_id, 'subway-visibility-settings-allowed-user-roles' ) ) {
392
-				$allowed_roles = get_post_meta( $post_id, 'subway-visibility-settings-allowed-user-roles', true );
393
-				if ( ! is_null( $allowed_roles ) ) {
390
+		if ( ! empty($post_id)) {
391
+			if (metadata_exists('post', $post_id, 'subway-visibility-settings-allowed-user-roles')) {
392
+				$allowed_roles = get_post_meta($post_id, 'subway-visibility-settings-allowed-user-roles', true);
393
+				if ( ! is_null($allowed_roles)) {
394 394
 					return $allowed_roles;
395 395
 				} else {
396 396
 					return false;
@@ -409,38 +409,38 @@  discard block
 block discarded – undo
409 409
 	 * @param  string $content The content of the post.
410 410
 	 * @return string The content of the post.
411 411
 	 */
412
-	public function showContentToAllowedRoles( $content ) {
412
+	public function showContentToAllowedRoles($content) {
413 413
 
414 414
 		$post_id = get_the_ID();
415
-		$allowed_user_roles = self::getAllowedUserRoles( $post_id );
415
+		$allowed_user_roles = self::getAllowedUserRoles($post_id);
416 416
 
417
-		if ( ! is_singular() && is_main_query() ) {
417
+		if ( ! is_singular() && is_main_query()) {
418 418
 			return $content;
419 419
 		}
420 420
 
421
-		if ( is_user_logged_in() ) {
421
+		if (is_user_logged_in()) {
422 422
 
423 423
 			$user = wp_get_current_user();
424 424
 
425
-			if ( ! is_array( $user->roles ) ) {
425
+			if ( ! is_array($user->roles)) {
426 426
 				$user->roles = (array) $user->roles;
427 427
 			}
428 428
 
429
-			$current_user_role = end( $user->roles );
429
+			$current_user_role = end($user->roles);
430 430
 
431
-			$no_privilege = '<div class="subway-role-not-allowed"><p>' . apply_filters( 'subway-content-restricted-to-role', esc_html__( 'You do not have the right privilege or role to view this page.', 'subway' ) ) . '</p></div>';
431
+			$no_privilege = '<div class="subway-role-not-allowed"><p>' . apply_filters('subway-content-restricted-to-role', esc_html__('You do not have the right privilege or role to view this page.', 'subway')) . '</p></div>';
432 432
 
433 433
 			// Restrict access to non admins only.
434
-			if ( ! current_user_can( 'manage_options' ) ) {
435
-				if ( is_array( $allowed_user_roles ) ) {
436
-					if ( ! in_array( $current_user_role, $allowed_user_roles ) ) {
434
+			if ( ! current_user_can('manage_options')) {
435
+				if (is_array($allowed_user_roles)) {
436
+					if ( ! in_array($current_user_role, $allowed_user_roles)) {
437 437
 						return $no_privilege;
438 438
 					}
439 439
 				}
440 440
 			}
441 441
 
442 442
 			// Return the content if the post is not yet saved.
443
-			if ( false === $allowed_user_roles ) {
443
+			if (false === $allowed_user_roles) {
444 444
 				return $content;
445 445
 			}
446 446
 		}
Please login to merge, or discard this patch.
classes/subway-enqueue.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 
20 20
 namespace Subway;
21 21
 
22
-if (! defined('ABSPATH') ) {
22
+if ( ! defined('ABSPATH')) {
23 23
     return;
24 24
 }
25 25
 
@@ -51,14 +51,14 @@  discard block
 block discarded – undo
51 51
         wp_enqueue_style('subway-style', SUBWAY_DIR_URL . 'assets/css/subway.css');
52 52
 
53 53
         // Only load the stylesheet and javascript documents inside our sign-in page.
54
-        if ($post_id === $signin_page ) {
54
+        if ($post_id === $signin_page) {
55 55
 
56
-            if (! is_user_logged_in() ) {
56
+            if ( ! is_user_logged_in()) {
57 57
 
58 58
                 wp_enqueue_script(
59 59
                     'subway-script', 
60 60
                     SUBWAY_DIR_URL . 'assets/js/subway.js', 
61
-                    array( 'jquery' )
61
+                    array('jquery')
62 62
                 );
63 63
 
64 64
                 wp_localize_script(
Please login to merge, or discard this patch.