@@ -22,7 +22,7 @@ discard block |
||
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 |
||
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 |
||
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,65 +106,65 @@ discard block |
||
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 | <input type="hidden" name="subway-visibility-form-submitted" value="1" /> |
126 | 126 | |
127 | - <?php if ( ! Options::isPublicSite() ) : ?> |
|
127 | + <?php if ( ! Options::isPublicSite()) : ?> |
|
128 | 128 | <?php // Site is private. Give them some Beer! ?> |
129 | 129 | <p> |
130 | 130 | <label class="subway-visibility-settings-checkbox-label" for="subway-visibility-public"> |
131 | - <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 ); ?>> |
|
132 | - <?php esc_html_e( 'Public', 'subway' ) ?> |
|
131 | + <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); ?>> |
|
132 | + <?php esc_html_e('Public', 'subway') ?> |
|
133 | 133 | </label> |
134 | 134 | </p> |
135 | 135 | <p> |
136 | 136 | <label class="subway-visibility-settings-checkbox-label" for="subway-visibility-private"> |
137 | 137 | <input type="radio" class="subway-visibility-settings-radio" id="subway-visibility-private" name="subway-visibility-settings" |
138 | - value="private" <?php echo checked( true, $is_post_private, false ); ?>> |
|
139 | - <?php esc_html_e( 'Members Only', 'subway' ) ?> |
|
138 | + value="private" <?php echo checked(true, $is_post_private, false); ?>> |
|
139 | + <?php esc_html_e('Members Only', 'subway') ?> |
|
140 | 140 | </label> |
141 | 141 | </p> |
142 | 142 | <div id="subway-roles-access-visibility-fields" class="hidden"> |
143 | 143 | <dl> |
144 | - <?php $post_allowed_user_roles = self::getAllowedUserRoles( $post->ID ); ?> |
|
144 | + <?php $post_allowed_user_roles = self::getAllowedUserRoles($post->ID); ?> |
|
145 | 145 | <?php $editable_roles = get_editable_roles(); ?> |
146 | 146 | <?php // Remove administrator for editable roles. ?> |
147 | - <?php unset( $editable_roles['administrator'] ); ?> |
|
148 | - <?php foreach ( $editable_roles as $role_name => $role_info ) { ?> |
|
147 | + <?php unset($editable_roles['administrator']); ?> |
|
148 | + <?php foreach ($editable_roles as $role_name => $role_info) { ?> |
|
149 | 149 | <dt> |
150 | - <?php $id = 'subway-visibility-settings-user-role-' . esc_html( $role_name ); ?> |
|
151 | - <label for="<?php echo esc_attr( $id ); ?>"> |
|
152 | - <?php if ( is_array( $post_allowed_user_roles ) && in_array( $role_name, $post_allowed_user_roles ) ) { ?> |
|
150 | + <?php $id = 'subway-visibility-settings-user-role-' . esc_html($role_name); ?> |
|
151 | + <label for="<?php echo esc_attr($id); ?>"> |
|
152 | + <?php if (is_array($post_allowed_user_roles) && in_array($role_name, $post_allowed_user_roles)) { ?> |
|
153 | 153 | <?php $checked = 'checked'; ?> |
154 | 154 | <?php } else { ?> |
155 | - <?php if ( false === $post_allowed_user_roles ) { ?> |
|
155 | + <?php if (false === $post_allowed_user_roles) { ?> |
|
156 | 156 | <?php $checked = 'checked'; ?> |
157 | 157 | <?php } else { ?> |
158 | 158 | <?php $checked = ''; ?> |
159 | 159 | <?php } ?> |
160 | 160 | <?php } ?> |
161 | - <input <?php echo esc_attr( $checked ); ?> id="<?php echo esc_attr( $id ); ?>" type="checkbox" |
|
162 | - name="subway-visibility-settings-user-role[]" class="subway-visibility-settings-role-access" value="<?php echo esc_attr( $role_name ); ?>" /> |
|
163 | - <?php echo esc_html( $role_info['name'] ); ?> |
|
161 | + <input <?php echo esc_attr($checked); ?> id="<?php echo esc_attr($id); ?>" type="checkbox" |
|
162 | + name="subway-visibility-settings-user-role[]" class="subway-visibility-settings-role-access" value="<?php echo esc_attr($role_name); ?>" /> |
|
163 | + <?php echo esc_html($role_info['name']); ?> |
|
164 | 164 | </label> |
165 | 165 | </dt> |
166 | 166 | <?php } ?> |
167 | - <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 | + <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> |
|
168 | 168 | </dl> |
169 | 169 | </div> |
170 | 170 | <script> |
@@ -181,11 +181,11 @@ discard block |
||
181 | 181 | }); |
182 | 182 | }); |
183 | 183 | </script> |
184 | - <p class="howto"><?php echo esc_html( $howto ); ?></p> |
|
184 | + <p class="howto"><?php echo esc_html($howto); ?></p> |
|
185 | 185 | <?php else : ?> |
186 | 186 | <?php // Site is public! Explain to them ?> |
187 | 187 | <p><em> |
188 | - <?php esc_html_e( 'You have chosen to make your site public inside Settings > Subway. Subway visibility options will be turned off.', 'subway' ); ?> |
|
188 | + <?php esc_html_e('You have chosen to make your site public inside Settings > Subway. Subway visibility options will be turned off.', 'subway'); ?> |
|
189 | 189 | </em> |
190 | 190 | </p> |
191 | 191 | <?php endif; ?> |
@@ -201,15 +201,15 @@ discard block |
||
201 | 201 | * @access public |
202 | 202 | * @return boolean false Returns false if nonce is not valid. |
203 | 203 | */ |
204 | - public function saveVisibilityMetabox( $post_id = '' ) { |
|
204 | + public function saveVisibilityMetabox($post_id = '') { |
|
205 | 205 | |
206 | - if ( wp_is_post_autosave( $post_id ) ) { |
|
206 | + if (wp_is_post_autosave($post_id)) { |
|
207 | 207 | return; |
208 | 208 | } |
209 | 209 | |
210 | - $is_form_submitted = filter_input( INPUT_POST, 'subway-visibility-form-submitted', FILTER_DEFAULT ); |
|
210 | + $is_form_submitted = filter_input(INPUT_POST, 'subway-visibility-form-submitted', FILTER_DEFAULT); |
|
211 | 211 | |
212 | - if ( ! $is_form_submitted ) { |
|
212 | + if ( ! $is_form_submitted) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
@@ -224,43 +224,43 @@ discard block |
||
224 | 224 | FILTER_SANITIZE_STRING |
225 | 225 | ); |
226 | 226 | |
227 | - $post_visibility = filter_input( INPUT_POST, $visibility_field, FILTER_SANITIZE_STRING ); |
|
227 | + $post_visibility = filter_input(INPUT_POST, $visibility_field, FILTER_SANITIZE_STRING); |
|
228 | 228 | |
229 | - $is_valid_visibility_nonce = self::isNonceValid( $visibility_nonce ); |
|
229 | + $is_valid_visibility_nonce = self::isNonceValid($visibility_nonce); |
|
230 | 230 | |
231 | - $allowed_roles = filter_input( INPUT_POST, 'subway-visibility-settings-user-role', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
231 | + $allowed_roles = filter_input(INPUT_POST, 'subway-visibility-settings-user-role', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
232 | 232 | |
233 | 233 | // verify taxonomies meta box nonce |
234 | - if ( false === $is_valid_visibility_nonce ) { |
|
234 | + if (false === $is_valid_visibility_nonce) { |
|
235 | 235 | return; |
236 | 236 | } |
237 | - if ( empty( $allowed_roles ) ) { |
|
237 | + if (empty($allowed_roles)) { |
|
238 | 238 | $allowed_roles = array(); |
239 | 239 | } |
240 | 240 | |
241 | 241 | // Update user roles. |
242 | - update_post_meta( $post_id, 'subway-visibility-settings-allowed-user-roles', $allowed_roles ); |
|
242 | + update_post_meta($post_id, 'subway-visibility-settings-allowed-user-roles', $allowed_roles); |
|
243 | 243 | |
244 | - if ( ! empty( $post_visibility ) ) { |
|
245 | - if ( ! empty( $post_id ) ) { |
|
246 | - if ( 'public' === $post_visibility ) { |
|
247 | - if ( ! in_array( $post_id, $public_posts ) ) { |
|
248 | - array_push( $public_posts, $post_id ); |
|
244 | + if ( ! empty($post_visibility)) { |
|
245 | + if ( ! empty($post_id)) { |
|
246 | + if ('public' === $post_visibility) { |
|
247 | + if ( ! in_array($post_id, $public_posts)) { |
|
248 | + array_push($public_posts, $post_id); |
|
249 | 249 | } |
250 | 250 | } |
251 | - if ( 'private' === $post_visibility ) { |
|
252 | - unset( $public_posts[ array_search( $post_id, $public_posts ) ] ); |
|
251 | + if ('private' === $post_visibility) { |
|
252 | + unset($public_posts[array_search($post_id, $public_posts)]); |
|
253 | 253 | } |
254 | 254 | } |
255 | 255 | } |
256 | 256 | |
257 | - if ( ! empty( $post_id ) ) { |
|
258 | - $posts_implode = implode( ', ', $public_posts ); |
|
257 | + if ( ! empty($post_id)) { |
|
258 | + $posts_implode = implode(', ', $public_posts); |
|
259 | 259 | |
260 | - if ( 'inherit' !== get_post_status( $post_id ) ) { |
|
260 | + if ('inherit' !== get_post_status($post_id)) { |
|
261 | 261 | |
262 | - if ( true === $is_valid_visibility_nonce ) { |
|
263 | - update_option( 'subway_public_post', $posts_implode ); |
|
262 | + if (true === $is_valid_visibility_nonce) { |
|
263 | + update_option('subway_public_post', $posts_implode); |
|
264 | 264 | update_post_meta( |
265 | 265 | $post_id, |
266 | 266 | self::VISIBILITY_METAKEY, |
@@ -280,9 +280,9 @@ discard block |
||
280 | 280 | * @access public |
281 | 281 | * @return boolean false Returns false if nonce is not valid. |
282 | 282 | */ |
283 | - public function saveMetaboxValues( $post_id ) { |
|
283 | + public function saveMetaboxValues($post_id) { |
|
284 | 284 | |
285 | - $this->saveVisibilityMetabox( $post_id ); |
|
285 | + $this->saveVisibilityMetabox($post_id); |
|
286 | 286 | return; |
287 | 287 | } |
288 | 288 | |
@@ -296,16 +296,16 @@ discard block |
||
296 | 296 | * @access public |
297 | 297 | * @return void |
298 | 298 | */ |
299 | - public static function getPostTypes( $args = '', $output = '' ) { |
|
299 | + public static function getPostTypes($args = '', $output = '') { |
|
300 | 300 | |
301 | - if ( empty( $args ) ) { |
|
301 | + if (empty($args)) { |
|
302 | 302 | $args = array( |
303 | 303 | 'public' => true, |
304 | 304 | ); |
305 | 305 | $output = 'names'; |
306 | 306 | } |
307 | 307 | |
308 | - $post_types = get_post_types( $args, $output ); |
|
308 | + $post_types = get_post_types($args, $output); |
|
309 | 309 | |
310 | 310 | return $post_types; |
311 | 311 | } |
@@ -319,9 +319,9 @@ discard block |
||
319 | 319 | * @access public |
320 | 320 | * @return boolean true Returns true if nonce is valid. |
321 | 321 | */ |
322 | - public function isNonceValid( $nonce ) { |
|
322 | + public function isNonceValid($nonce) { |
|
323 | 323 | |
324 | - if ( ! isset( $nonce ) || ! wp_verify_nonce( $nonce, basename( __FILE__ ) ) ) { |
|
324 | + if ( ! isset($nonce) || ! wp_verify_nonce($nonce, basename(__FILE__))) { |
|
325 | 325 | return; |
326 | 326 | } |
327 | 327 | |
@@ -337,23 +337,23 @@ discard block |
||
337 | 337 | * @access public |
338 | 338 | * @return boolean true Returns true if post is private. Otherwise false. |
339 | 339 | */ |
340 | - public static function isPostPrivate( $post_id ) { |
|
340 | + public static function isPostPrivate($post_id) { |
|
341 | 341 | |
342 | 342 | $meta_value = ''; |
343 | 343 | |
344 | - if ( ! empty( $post_id ) ) { |
|
345 | - $meta_value = get_post_meta( $post_id, self::VISIBILITY_METAKEY, true ); |
|
344 | + if ( ! empty($post_id)) { |
|
345 | + $meta_value = get_post_meta($post_id, self::VISIBILITY_METAKEY, true); |
|
346 | 346 | |
347 | 347 | // New page or old pages that don't have Subway'\ Visibility Options |
348 | - if ( empty( $meta_value ) ) { |
|
348 | + if (empty($meta_value)) { |
|
349 | 349 | // Get the value from the general settings (Settings > Subway) |
350 | 350 | $is_site_public = Options::isPublicSite(); |
351 | - if ( ! $is_site_public ) { |
|
351 | + if ( ! $is_site_public) { |
|
352 | 352 | // It's private. |
353 | 353 | return true; |
354 | 354 | } |
355 | 355 | } |
356 | - if ( 'private' === $meta_value ) { |
|
356 | + if ('private' === $meta_value) { |
|
357 | 357 | return true; |
358 | 358 | } |
359 | 359 | } |
@@ -370,12 +370,12 @@ discard block |
||
370 | 370 | * @access public |
371 | 371 | * @return boolean true Returns true if post is public. Otherwise false. |
372 | 372 | */ |
373 | - public static function isPostPublic( $post_id ) { |
|
373 | + public static function isPostPublic($post_id) { |
|
374 | 374 | |
375 | 375 | $public_post = Options::getPublicPostsIdentifiers(); |
376 | 376 | |
377 | - if ( ! empty( $post_id ) ) { |
|
378 | - if ( ! in_array( $post_id, $public_post, true ) ) { |
|
377 | + if ( ! empty($post_id)) { |
|
378 | + if ( ! in_array($post_id, $public_post, true)) { |
|
379 | 379 | return true; |
380 | 380 | } |
381 | 381 | } |
@@ -389,16 +389,16 @@ discard block |
||
389 | 389 | * @param integer $post_id The post ID. |
390 | 390 | * @return mixed Boolean false if metadata does not exists. Otherwise, return the array value of meta. |
391 | 391 | */ |
392 | - public static function getAllowedUserRoles( $post_id = 0 ) { |
|
392 | + public static function getAllowedUserRoles($post_id = 0) { |
|
393 | 393 | |
394 | 394 | $allowed_roles = array(); |
395 | 395 | |
396 | - if ( ! empty( $post_id ) ) { |
|
396 | + if ( ! empty($post_id)) { |
|
397 | 397 | |
398 | 398 | // Check if metadata exists for the following post. |
399 | - if ( metadata_exists( 'post', $post_id, 'subway-visibility-settings-allowed-user-roles' ) ) { |
|
400 | - $allowed_roles = get_post_meta( $post_id, 'subway-visibility-settings-allowed-user-roles', true ); |
|
401 | - if ( ! is_null( $allowed_roles ) ) { |
|
399 | + if (metadata_exists('post', $post_id, 'subway-visibility-settings-allowed-user-roles')) { |
|
400 | + $allowed_roles = get_post_meta($post_id, 'subway-visibility-settings-allowed-user-roles', true); |
|
401 | + if ( ! is_null($allowed_roles)) { |
|
402 | 402 | return $allowed_roles; |
403 | 403 | } |
404 | 404 | return false; |
@@ -420,38 +420,38 @@ discard block |
||
420 | 420 | * @param string $content The content of the post. |
421 | 421 | * @return string The content of the post. |
422 | 422 | */ |
423 | - public function showContentToAllowedRoles( $content ) { |
|
423 | + public function showContentToAllowedRoles($content) { |
|
424 | 424 | |
425 | 425 | $post_id = get_the_ID(); |
426 | - $allowed_user_roles = self::getAllowedUserRoles( $post_id ); |
|
426 | + $allowed_user_roles = self::getAllowedUserRoles($post_id); |
|
427 | 427 | |
428 | - if ( ! is_singular() && is_main_query() ) { |
|
428 | + if ( ! is_singular() && is_main_query()) { |
|
429 | 429 | return $content; |
430 | 430 | } |
431 | 431 | |
432 | - if ( is_user_logged_in() ) { |
|
432 | + if (is_user_logged_in()) { |
|
433 | 433 | |
434 | 434 | $user = wp_get_current_user(); |
435 | 435 | |
436 | - if ( ! is_array( $user->roles ) ) { |
|
436 | + if ( ! is_array($user->roles)) { |
|
437 | 437 | $user->roles = (array) $user->roles; |
438 | 438 | } |
439 | 439 | |
440 | - $current_user_role = end( $user->roles ); |
|
440 | + $current_user_role = end($user->roles); |
|
441 | 441 | |
442 | - $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>'; |
|
442 | + $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>'; |
|
443 | 443 | |
444 | 444 | // Restrict access to non admins only. |
445 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
446 | - if ( is_array( $allowed_user_roles ) ) { |
|
447 | - if ( ! in_array( $current_user_role, $allowed_user_roles ) ) { |
|
445 | + if ( ! current_user_can('manage_options')) { |
|
446 | + if (is_array($allowed_user_roles)) { |
|
447 | + if ( ! in_array($current_user_role, $allowed_user_roles)) { |
|
448 | 448 | return $no_privilege; |
449 | 449 | } |
450 | 450 | } |
451 | 451 | } |
452 | 452 | |
453 | 453 | // Return the content if the post is not yet saved. |
454 | - if ( false === $allowed_user_roles ) { |
|
454 | + if (false === $allowed_user_roles) { |
|
455 | 455 | return $content; |
456 | 456 | } |
457 | 457 | } |
@@ -182,10 +182,13 @@ |
||
182 | 182 | }); |
183 | 183 | </script> |
184 | 184 | <p class="howto"><?php echo esc_html( $howto ); ?></p> |
185 | - <?php else : ?> |
|
185 | + <?php else { |
|
186 | + : ?> |
|
186 | 187 | <?php // Site is public! Explain to them ?> |
187 | 188 | <p><em> |
188 | - <?php esc_html_e( 'You have chosen to make your site public inside Settings > Subway. Subway visibility options will be turned off.', 'subway' ); ?> |
|
189 | + <?php esc_html_e( 'You have chosen to make your site public inside Settings > Subway. Subway visibility options will be turned off.', 'subway' ); |
|
190 | +} |
|
191 | +?> |
|
189 | 192 | </em> |
190 | 193 | </p> |
191 | 194 | <?php endif; ?> |