@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | namespace Subway; |
21 | 21 | |
22 | 22 | if (! defined('ABSPATH') ) { |
23 | - return; |
|
23 | + return; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -36,55 +36,55 @@ discard block |
||
36 | 36 | final class AdminSettings |
37 | 37 | { |
38 | 38 | |
39 | - /** |
|
40 | - * Our class constructor |
|
41 | - */ |
|
42 | - public function __construct() |
|
43 | - { |
|
39 | + /** |
|
40 | + * Our class constructor |
|
41 | + */ |
|
42 | + public function __construct() |
|
43 | + { |
|
44 | 44 | |
45 | - add_action('admin_menu', array( $this, 'adminMenu' )); |
|
45 | + add_action('admin_menu', array( $this, 'adminMenu' )); |
|
46 | 46 | |
47 | - add_action('admin_init', array( $this, 'registerSettings' )); |
|
47 | + add_action('admin_init', array( $this, 'registerSettings' )); |
|
48 | 48 | |
49 | - } |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Display 'Subway' link under 'Settings' |
|
53 | - * |
|
54 | - * @return void |
|
55 | - */ |
|
56 | - public function adminMenu() |
|
57 | - { |
|
51 | + /** |
|
52 | + * Display 'Subway' link under 'Settings' |
|
53 | + * |
|
54 | + * @return void |
|
55 | + */ |
|
56 | + public function adminMenu() |
|
57 | + { |
|
58 | 58 | |
59 | - add_options_page( |
|
60 | - 'Subway Settings', 'Subway', 'manage_options', |
|
61 | - 'subway', array( $this, 'optionsPage' ) |
|
62 | - ); |
|
59 | + add_options_page( |
|
60 | + 'Subway Settings', 'Subway', 'manage_options', |
|
61 | + 'subway', array( $this, 'optionsPage' ) |
|
62 | + ); |
|
63 | 63 | |
64 | 64 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueueSettingsScripts' ) ); |
65 | 65 | |
66 | - return; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Registers all settings related to Subway. |
|
71 | - * |
|
72 | - * @return void |
|
73 | - */ |
|
74 | - public function registerSettings() |
|
75 | - { |
|
76 | - |
|
77 | - // Register our settings section. |
|
78 | - add_settings_section( |
|
79 | - 'subway-page-visibility-section', __('Pages Visibility', 'subway'), |
|
80 | - array( $this, 'sectionCallback' ), 'subway-settings-section' |
|
81 | - ); |
|
82 | - |
|
83 | - // Register Redirect Options pages. |
|
84 | - add_settings_section( |
|
85 | - 'subway-redirect-section', __('Redirect Options', 'subway'), |
|
86 | - array( $this, 'redirectCallback' ), 'subway-settings-section' |
|
87 | - ); |
|
66 | + return; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Registers all settings related to Subway. |
|
71 | + * |
|
72 | + * @return void |
|
73 | + */ |
|
74 | + public function registerSettings() |
|
75 | + { |
|
76 | + |
|
77 | + // Register our settings section. |
|
78 | + add_settings_section( |
|
79 | + 'subway-page-visibility-section', __('Pages Visibility', 'subway'), |
|
80 | + array( $this, 'sectionCallback' ), 'subway-settings-section' |
|
81 | + ); |
|
82 | + |
|
83 | + // Register Redirect Options pages. |
|
84 | + add_settings_section( |
|
85 | + 'subway-redirect-section', __('Redirect Options', 'subway'), |
|
86 | + array( $this, 'redirectCallback' ), 'subway-settings-section' |
|
87 | + ); |
|
88 | 88 | |
89 | 89 | $is_public_site = Options::isPublicSite(); |
90 | 90 | $hidden_class = ''; |
@@ -93,127 +93,127 @@ discard block |
||
93 | 93 | $hidden_class = 'hidden'; |
94 | 94 | } |
95 | 95 | |
96 | - // Register the fields. |
|
97 | - $fields = array( |
|
96 | + // Register the fields. |
|
97 | + $fields = array( |
|
98 | 98 | |
99 | - array( |
|
100 | - 'id' => 'subway_login_page', |
|
101 | - 'label' => __('Login Page', 'subway'), |
|
102 | - 'callback' => 'subway_login_page_form', |
|
103 | - 'section' => 'subway-settings-section', |
|
104 | - 'group' => 'subway-page-visibility-section', |
|
99 | + array( |
|
100 | + 'id' => 'subway_login_page', |
|
101 | + 'label' => __('Login Page', 'subway'), |
|
102 | + 'callback' => 'subway_login_page_form', |
|
103 | + 'section' => 'subway-settings-section', |
|
104 | + 'group' => 'subway-page-visibility-section', |
|
105 | 105 | 'args' => array( |
106 | 106 | 'label_for' => 'subway_login_page', |
107 | 107 | 'class' => 'subway_login_page-option', |
108 | 108 | ), |
109 | - ), |
|
110 | - array( |
|
111 | - 'id' => 'subway_public_post_deprecated', |
|
112 | - 'label' => __('Public Posts IDs', 'subway'), |
|
113 | - 'callback' => 'subway_public_post', |
|
114 | - 'section' => 'subway-settings-section', |
|
115 | - 'group' => 'subway-page-visibility-section', |
|
109 | + ), |
|
110 | + array( |
|
111 | + 'id' => 'subway_public_post_deprecated', |
|
112 | + 'label' => __('Public Posts IDs', 'subway'), |
|
113 | + 'callback' => 'subway_public_post', |
|
114 | + 'section' => 'subway-settings-section', |
|
115 | + 'group' => 'subway-page-visibility-section', |
|
116 | 116 | 'args' => array( |
117 | 117 | 'label_for' => 'subway_public_post_deprecated', |
118 | 118 | 'class' => 'subway_public_post_deprecated-option ' . $hidden_class, |
119 | 119 | ), |
120 | - ), |
|
121 | - array( |
|
122 | - 'id' => 'subway_is_public', |
|
123 | - 'label' => __('Public Website', 'subway'), |
|
124 | - 'callback' => 'subway_is_public_form', |
|
125 | - 'section' => 'subway-settings-section', |
|
126 | - 'group' => 'subway-page-visibility-section', |
|
127 | - 'args' => array( |
|
128 | - 'label_for' => 'subway_is_public', |
|
129 | - 'class' => 'subway_is_public-option', |
|
130 | - ), |
|
131 | - ), |
|
132 | - |
|
133 | - array( |
|
134 | - 'id' => 'subway_redirect_type', |
|
135 | - 'label' => __('Redirect Type', 'subway'), |
|
136 | - 'callback' => 'subway_redirect_option_form', |
|
137 | - 'section' => 'subway-settings-section', |
|
138 | - 'group' => 'subway-redirect-section', |
|
120 | + ), |
|
121 | + array( |
|
122 | + 'id' => 'subway_is_public', |
|
123 | + 'label' => __('Public Website', 'subway'), |
|
124 | + 'callback' => 'subway_is_public_form', |
|
125 | + 'section' => 'subway-settings-section', |
|
126 | + 'group' => 'subway-page-visibility-section', |
|
127 | + 'args' => array( |
|
128 | + 'label_for' => 'subway_is_public', |
|
129 | + 'class' => 'subway_is_public-option', |
|
130 | + ), |
|
131 | + ), |
|
132 | + |
|
133 | + array( |
|
134 | + 'id' => 'subway_redirect_type', |
|
135 | + 'label' => __('Redirect Type', 'subway'), |
|
136 | + 'callback' => 'subway_redirect_option_form', |
|
137 | + 'section' => 'subway-settings-section', |
|
138 | + 'group' => 'subway-redirect-section', |
|
139 | 139 | 'args' => array( |
140 | 140 | 'label_for' => 'subway_redirect_type', |
141 | 141 | 'class' => 'subway_redirect_type-option ' . $hidden_class, |
142 | 142 | ), |
143 | - ), |
|
144 | - array( |
|
145 | - 'id' => 'subway_redirect_wp_admin', |
|
146 | - 'label' => __('WP Login Link', 'subway'), |
|
147 | - 'callback' => 'subway_lock_wp_admin', |
|
148 | - 'section' => 'subway-settings-section', |
|
149 | - 'group' => 'subway-redirect-section', |
|
143 | + ), |
|
144 | + array( |
|
145 | + 'id' => 'subway_redirect_wp_admin', |
|
146 | + 'label' => __('WP Login Link', 'subway'), |
|
147 | + 'callback' => 'subway_lock_wp_admin', |
|
148 | + 'section' => 'subway-settings-section', |
|
149 | + 'group' => 'subway-redirect-section', |
|
150 | 150 | 'args' => array( |
151 | 151 | 'label_for' => 'subway_redirect_wp_admin', |
152 | 152 | 'class' => 'subway_redirect_wp_admin-option ' . $hidden_class, |
153 | 153 | ), |
154 | - ), |
|
155 | - ); |
|
154 | + ), |
|
155 | + ); |
|
156 | 156 | |
157 | - foreach ( $fields as $field ) { |
|
157 | + foreach ( $fields as $field ) { |
|
158 | 158 | |
159 | - add_settings_field( |
|
160 | - $field['id'], $field['label'], |
|
161 | - $field['callback'], $field['section'], |
|
162 | - $field['group'], $field['args'] |
|
163 | - ); |
|
159 | + add_settings_field( |
|
160 | + $field['id'], $field['label'], |
|
161 | + $field['callback'], $field['section'], |
|
162 | + $field['group'], $field['args'] |
|
163 | + ); |
|
164 | 164 | |
165 | - register_setting('subway-settings-group', $field['id']); |
|
165 | + register_setting('subway-settings-group', $field['id']); |
|
166 | 166 | |
167 | - $file = str_replace('_', '-', $field['callback']); |
|
167 | + $file = str_replace('_', '-', $field['callback']); |
|
168 | 168 | |
169 | - include_once trailingslashit(SUBWAY_DIR_PATH) . |
|
170 | - 'settings-fields/field-' . sanitize_title($file) . '.php'; |
|
169 | + include_once trailingslashit(SUBWAY_DIR_PATH) . |
|
170 | + 'settings-fields/field-' . sanitize_title($file) . '.php'; |
|
171 | 171 | |
172 | - } |
|
172 | + } |
|
173 | 173 | |
174 | - // Register Redirect Page ID Settings. |
|
175 | - register_setting('subway-settings-group', 'subway_redirect_page_id'); |
|
174 | + // Register Redirect Page ID Settings. |
|
175 | + register_setting('subway-settings-group', 'subway_redirect_page_id'); |
|
176 | 176 | |
177 | - // Register Redirect Custom URL Settings. |
|
178 | - register_setting('subway-settings-group', 'subway_redirect_custom_url'); |
|
177 | + // Register Redirect Custom URL Settings. |
|
178 | + register_setting('subway-settings-group', 'subway_redirect_custom_url'); |
|
179 | 179 | |
180 | 180 | $this->registerSettingsScripts(); |
181 | 181 | |
182 | - return; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Callback function for the first Section. |
|
187 | - * |
|
188 | - * @return void |
|
189 | - */ |
|
190 | - public function sectionCallback() |
|
191 | - { |
|
192 | - echo esc_html_e( |
|
193 | - 'All settings related to the |
|
182 | + return; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Callback function for the first Section. |
|
187 | + * |
|
188 | + * @return void |
|
189 | + */ |
|
190 | + public function sectionCallback() |
|
191 | + { |
|
192 | + echo esc_html_e( |
|
193 | + 'All settings related to the |
|
194 | 194 | visibility of your site and pages.', 'subway' |
195 | - ); |
|
196 | - return; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Callback function for the second Section. |
|
201 | - * |
|
202 | - * @return void |
|
203 | - */ |
|
204 | - public function redirectCallback() |
|
205 | - { |
|
206 | - return; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Renders the 'wrapper' for our options pages. |
|
211 | - * |
|
212 | - * @return void |
|
213 | - */ |
|
214 | - public function optionsPage() |
|
215 | - { |
|
216 | - ?> |
|
195 | + ); |
|
196 | + return; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Callback function for the second Section. |
|
201 | + * |
|
202 | + * @return void |
|
203 | + */ |
|
204 | + public function redirectCallback() |
|
205 | + { |
|
206 | + return; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Renders the 'wrapper' for our options pages. |
|
211 | + * |
|
212 | + * @return void |
|
213 | + */ |
|
214 | + public function optionsPage() |
|
215 | + { |
|
216 | + ?> |
|
217 | 217 | |
218 | 218 | <div class="wrap"> |
219 | 219 | <h2> |
@@ -227,30 +227,30 @@ discard block |
||
227 | 227 | </div> |
228 | 228 | |
229 | 229 | <?php |
230 | - } |
|
230 | + } |
|
231 | 231 | |
232 | 232 | /** |
233 | - * Registers the scipts for the Subway settings page. |
|
234 | - * |
|
233 | + * Registers the scipts for the Subway settings page. |
|
234 | + * |
|
235 | 235 | * @since 2.0.9 |
236 | - * @access public |
|
237 | - * @return void |
|
238 | - */ |
|
236 | + * @access public |
|
237 | + * @return void |
|
238 | + */ |
|
239 | 239 | public function registerSettingsScripts() { |
240 | 240 | |
241 | 241 | // Registers the Subway settings Javascript. |
242 | - wp_register_script( 'subway-settings-script', plugins_url('/assets/js/settings.js', __FILE__) ); |
|
243 | - wp_register_style( 'subway-settings-style', plugins_url('/assets/css/settings.css', __FILE__) ); |
|
242 | + wp_register_script( 'subway-settings-script', plugins_url('/assets/js/settings.js', __FILE__) ); |
|
243 | + wp_register_style( 'subway-settings-style', plugins_url('/assets/css/settings.css', __FILE__) ); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
247 | - * Loads the scipts for the Subway settings page. |
|
247 | + * Loads the scipts for the Subway settings page. |
|
248 | 248 | * |
249 | 249 | * @since 2.0.9 |
250 | - * @access public |
|
251 | - * @return void |
|
252 | - * @return void |
|
253 | - */ |
|
250 | + * @access public |
|
251 | + * @return void |
|
252 | + * @return void |
|
253 | + */ |
|
254 | 254 | public function enqueueSettingsScripts( $hook ) { |
255 | 255 | // Checks if page hook is Subway settings page. |
256 | 256 | if ( 'settings_page_subway' === $hook ) { |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | namespace Subway; |
22 | 22 | |
23 | 23 | if (! defined('ABSPATH') ) { |
24 | - return; |
|
24 | + return; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -37,99 +37,99 @@ discard block |
||
37 | 37 | final class Metabox |
38 | 38 | { |
39 | 39 | |
40 | - /** |
|
41 | - * Subway visibility meta value, |
|
42 | - * |
|
43 | - * @since 2.0.9 |
|
44 | - * @const string VISIBILITY_METAKEY |
|
45 | - */ |
|
46 | - const VISIBILITY_METAKEY = 'subway_visibility_meta_key'; |
|
47 | - |
|
48 | - /** |
|
49 | - * Registers and update metabox with its intended method below. |
|
50 | - * |
|
51 | - * @since 2.0.9 |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function __construct() |
|
55 | - { |
|
56 | - add_action( |
|
57 | - 'add_meta_boxes', |
|
58 | - array( |
|
59 | - $this, |
|
60 | - 'addMetabox' |
|
61 | - ) |
|
62 | - ); |
|
63 | - add_action( |
|
64 | - 'save_post', |
|
65 | - array( |
|
66 | - $this, |
|
67 | - 'saveMetaboxValues' |
|
68 | - ) |
|
69 | - ); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Initialize metabox |
|
74 | - * |
|
75 | - * @since 2.0.9 |
|
76 | - * @access public |
|
77 | - * @return void |
|
78 | - */ |
|
79 | - public static function initMetabox() |
|
80 | - { |
|
81 | - new Metabox(); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Initialize metabox |
|
86 | - * |
|
87 | - * @since 2.0.9 |
|
88 | - * @access public |
|
89 | - * @return void |
|
90 | - */ |
|
91 | - public function addMetabox() |
|
92 | - { |
|
93 | - $post_types = $this->getPostTypes(); |
|
94 | - |
|
95 | - foreach ( $post_types as $post_type => $value ) { |
|
96 | - add_meta_box( |
|
97 | - 'subway_visibility_metabox', |
|
98 | - esc_html__('Subway: Visibility Option', 'subway'), |
|
99 | - array( $this, 'visibilityMetabox' ), |
|
100 | - $post_type, |
|
101 | - 'side', |
|
102 | - 'low' |
|
103 | - ); |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * This method displays the Subway Visibility checkbox. |
|
109 | - * |
|
110 | - * @param object $post Contains data from the current post. |
|
111 | - * |
|
112 | - * @since 2.0.9 |
|
113 | - * @access public |
|
114 | - * @return void |
|
115 | - */ |
|
116 | - public function visibilityMetabox( $post ) |
|
117 | - { |
|
118 | - $howto = __( |
|
119 | - 'Choose the accessibility of this page from the options above.', |
|
120 | - 'subway' |
|
121 | - ); |
|
40 | + /** |
|
41 | + * Subway visibility meta value, |
|
42 | + * |
|
43 | + * @since 2.0.9 |
|
44 | + * @const string VISIBILITY_METAKEY |
|
45 | + */ |
|
46 | + const VISIBILITY_METAKEY = 'subway_visibility_meta_key'; |
|
47 | + |
|
48 | + /** |
|
49 | + * Registers and update metabox with its intended method below. |
|
50 | + * |
|
51 | + * @since 2.0.9 |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function __construct() |
|
55 | + { |
|
56 | + add_action( |
|
57 | + 'add_meta_boxes', |
|
58 | + array( |
|
59 | + $this, |
|
60 | + 'addMetabox' |
|
61 | + ) |
|
62 | + ); |
|
63 | + add_action( |
|
64 | + 'save_post', |
|
65 | + array( |
|
66 | + $this, |
|
67 | + 'saveMetaboxValues' |
|
68 | + ) |
|
69 | + ); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Initialize metabox |
|
74 | + * |
|
75 | + * @since 2.0.9 |
|
76 | + * @access public |
|
77 | + * @return void |
|
78 | + */ |
|
79 | + public static function initMetabox() |
|
80 | + { |
|
81 | + new Metabox(); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Initialize metabox |
|
86 | + * |
|
87 | + * @since 2.0.9 |
|
88 | + * @access public |
|
89 | + * @return void |
|
90 | + */ |
|
91 | + public function addMetabox() |
|
92 | + { |
|
93 | + $post_types = $this->getPostTypes(); |
|
94 | + |
|
95 | + foreach ( $post_types as $post_type => $value ) { |
|
96 | + add_meta_box( |
|
97 | + 'subway_visibility_metabox', |
|
98 | + esc_html__('Subway: Visibility Option', 'subway'), |
|
99 | + array( $this, 'visibilityMetabox' ), |
|
100 | + $post_type, |
|
101 | + 'side', |
|
102 | + 'low' |
|
103 | + ); |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * This method displays the Subway Visibility checkbox. |
|
109 | + * |
|
110 | + * @param object $post Contains data from the current post. |
|
111 | + * |
|
112 | + * @since 2.0.9 |
|
113 | + * @access public |
|
114 | + * @return void |
|
115 | + */ |
|
116 | + public function visibilityMetabox( $post ) |
|
117 | + { |
|
118 | + $howto = __( |
|
119 | + 'Choose the accessibility of this page from the options above.', |
|
120 | + 'subway' |
|
121 | + ); |
|
122 | 122 | |
123 | - $private_setting_label = __( 'Members Only', 'subway' ); |
|
123 | + $private_setting_label = __( 'Members Only', 'subway' ); |
|
124 | 124 | |
125 | - $is_post_public = self::isPostPublic($post->ID); |
|
126 | - $is_post_private = self::isPostPrivate($post->ID); |
|
125 | + $is_post_public = self::isPostPublic($post->ID); |
|
126 | + $is_post_private = self::isPostPrivate($post->ID); |
|
127 | 127 | |
128 | - // Make sure the form request comes from WordPress |
|
129 | - wp_nonce_field( basename(__FILE__), 'subway_post_visibility_nonce' ); |
|
128 | + // Make sure the form request comes from WordPress |
|
129 | + wp_nonce_field( basename(__FILE__), 'subway_post_visibility_nonce' ); |
|
130 | 130 | |
131 | - // Disable the options (radio) when site is selected as public |
|
132 | - ?> |
|
131 | + // Disable the options (radio) when site is selected as public |
|
132 | + ?> |
|
133 | 133 | |
134 | 134 | <?php if ( ! Options::isPublicSite() ): ?> |
135 | 135 | <?php // Site is private. Give them some Beer! ?> |
@@ -155,188 +155,188 @@ discard block |
||
155 | 155 | </p> |
156 | 156 | <?php endif; ?> |
157 | 157 | <?php |
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * This method verify if nonce is valid then updates a post_meta. |
|
162 | - * |
|
163 | - * @param integer $post_id Contains ID of the current post. |
|
164 | - * |
|
165 | - * @since 2.0.9 |
|
166 | - * @access public |
|
167 | - * @return boolean false Returns false if nonce is not valid. |
|
168 | - */ |
|
169 | - public function saveVisibilityMetabox( $post_id = '' ) |
|
170 | - { |
|
171 | - |
|
172 | - $public_posts = Options::getPublicPostsIdentifiers(); |
|
173 | - |
|
174 | - $posts_implode = ''; |
|
175 | - |
|
176 | - $visibility_field = 'subway-visibility-settings'; |
|
177 | - |
|
178 | - $visibility_nonce = filter_input( |
|
179 | - INPUT_POST, |
|
180 | - 'subway_post_visibility_nonce', |
|
181 | - FILTER_SANITIZE_STRING |
|
182 | - ); |
|
183 | - |
|
184 | - $post_visibility = filter_input( |
|
185 | - INPUT_POST, |
|
186 | - $visibility_field, |
|
187 | - FILTER_SANITIZE_STRING |
|
188 | - ); |
|
189 | - |
|
190 | - $is_valid_visibility_nonce = self::isNonceValid( |
|
191 | - $visibility_nonce |
|
192 | - ); |
|
193 | - |
|
194 | - // verify taxonomies meta box nonce |
|
195 | - if (false === $is_valid_visibility_nonce ) { |
|
196 | - return; |
|
197 | - } |
|
198 | - |
|
199 | - if (! empty($post_visibility) ) { |
|
200 | - if (! empty($post_id) ) { |
|
201 | - if ('public' === $post_visibility ) { |
|
202 | - if (! in_array($post_id, $public_posts) ) { |
|
203 | - array_push($public_posts, $post_id); |
|
204 | - } |
|
205 | - } |
|
206 | - if ('private' === $post_visibility ) { |
|
207 | - unset($public_posts[ array_search($post_id, $public_posts) ]); |
|
208 | - } |
|
209 | - } |
|
210 | - } |
|
211 | - |
|
212 | - if (! empty($post_id) ) { |
|
213 | - $posts_implode = implode(", ", $public_posts); |
|
214 | - |
|
215 | - if ('inherit' !== get_post_status($post_id) ) { |
|
216 | - |
|
217 | - if (true === $is_valid_visibility_nonce ) { |
|
218 | - update_option('subway_public_post', $posts_implode); |
|
219 | - update_post_meta( |
|
220 | - $post_id, |
|
221 | - self::VISIBILITY_METAKEY, |
|
222 | - $post_visibility |
|
223 | - ); |
|
224 | - } |
|
225 | - |
|
226 | - } |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * This method runs the methods that handles the update for a post_meta. |
|
232 | - * |
|
233 | - * @param integer $post_id Contains ID of the current post. |
|
234 | - * |
|
235 | - * @since 2.0.9 |
|
236 | - * @access public |
|
237 | - * @return boolean false Returns false if nonce is not valid. |
|
238 | - */ |
|
239 | - public function saveMetaboxValues( $post_id ) |
|
240 | - { |
|
241 | - $this->saveVisibilityMetabox($post_id); |
|
242 | - return; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * Initialize metabox arguments. |
|
247 | - * |
|
248 | - * @param array $args The arguments for the get_post_types(). |
|
249 | - * @param string $output Your desired output for the data. |
|
250 | - * |
|
251 | - * @since 2.0.9 |
|
252 | - * @access public |
|
253 | - * @return void |
|
254 | - */ |
|
255 | - public static function getPostTypes( $args = '', $output = '' ) |
|
256 | - { |
|
257 | - if (empty($args) ) { |
|
258 | - $args = array( |
|
259 | - 'public' => true, |
|
260 | - ); |
|
261 | - $output = 'names'; |
|
262 | - } |
|
263 | - |
|
264 | - $post_types = get_post_types($args, $output); |
|
265 | - |
|
266 | - return $post_types; |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * This method verify if nonce is valid. |
|
271 | - * |
|
272 | - * @param mixed $nonce the name of a metabox nonce. |
|
273 | - * |
|
274 | - * @since 2.0.9 |
|
275 | - * @access public |
|
276 | - * @return boolean true Returns true if nonce is valid. |
|
277 | - */ |
|
278 | - public function isNonceValid( $nonce ) |
|
279 | - { |
|
280 | - if (!isset($nonce) || !wp_verify_nonce($nonce, basename(__FILE__)) ) { |
|
281 | - return; |
|
282 | - } |
|
283 | - |
|
284 | - return true; |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * Checks if a post is set to private. |
|
289 | - * |
|
290 | - * @param integer $post_id Contains ID of the current post. |
|
291 | - * |
|
292 | - * @since 2.0.9 |
|
293 | - * @access public |
|
294 | - * @return boolean true Returns true if post is private. Otherwise false. |
|
295 | - */ |
|
296 | - public static function isPostPrivate( $post_id ) |
|
297 | - { |
|
298 | - $meta_value = ''; |
|
299 | - |
|
300 | - if ( ! empty( $post_id ) ) { |
|
301 | - $meta_value = get_post_meta($post_id, self::VISIBILITY_METAKEY, true); |
|
302 | - |
|
303 | - // New page or old pages that don't have Subway'\ Visibility Options |
|
304 | - if ( empty ( $meta_value ) ) { |
|
305 | - // Get the value from the general settings (Settings > Subway) |
|
306 | - $is_site_public = Options::isPublicSite(); |
|
307 | - if ( ! $is_site_public ) { |
|
308 | - // It's private. |
|
309 | - return true; |
|
310 | - } |
|
311 | - } |
|
312 | - if ('private' === $meta_value ) { |
|
313 | - return true; |
|
314 | - } |
|
315 | - } |
|
316 | - |
|
317 | - return false; |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * Checks if a post is set to public. |
|
322 | - * |
|
323 | - * @param integer $post_id Contains ID of the current post. |
|
324 | - * |
|
325 | - * @since 2.0.9 |
|
326 | - * @access public |
|
327 | - * @return boolean true Returns true if post is public. Otherwise false. |
|
328 | - */ |
|
329 | - public static function isPostPublic( $post_id ) |
|
330 | - { |
|
331 | - $public_post = Options::getPublicPostsIdentifiers(); |
|
332 | - |
|
333 | - if (! empty($post_id) ) { |
|
334 | - if (! in_array($post_id, $public_post, true) ) { |
|
335 | - return true; |
|
336 | - } |
|
337 | - } |
|
338 | - |
|
339 | - return false; |
|
340 | - } |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * This method verify if nonce is valid then updates a post_meta. |
|
162 | + * |
|
163 | + * @param integer $post_id Contains ID of the current post. |
|
164 | + * |
|
165 | + * @since 2.0.9 |
|
166 | + * @access public |
|
167 | + * @return boolean false Returns false if nonce is not valid. |
|
168 | + */ |
|
169 | + public function saveVisibilityMetabox( $post_id = '' ) |
|
170 | + { |
|
171 | + |
|
172 | + $public_posts = Options::getPublicPostsIdentifiers(); |
|
173 | + |
|
174 | + $posts_implode = ''; |
|
175 | + |
|
176 | + $visibility_field = 'subway-visibility-settings'; |
|
177 | + |
|
178 | + $visibility_nonce = filter_input( |
|
179 | + INPUT_POST, |
|
180 | + 'subway_post_visibility_nonce', |
|
181 | + FILTER_SANITIZE_STRING |
|
182 | + ); |
|
183 | + |
|
184 | + $post_visibility = filter_input( |
|
185 | + INPUT_POST, |
|
186 | + $visibility_field, |
|
187 | + FILTER_SANITIZE_STRING |
|
188 | + ); |
|
189 | + |
|
190 | + $is_valid_visibility_nonce = self::isNonceValid( |
|
191 | + $visibility_nonce |
|
192 | + ); |
|
193 | + |
|
194 | + // verify taxonomies meta box nonce |
|
195 | + if (false === $is_valid_visibility_nonce ) { |
|
196 | + return; |
|
197 | + } |
|
198 | + |
|
199 | + if (! empty($post_visibility) ) { |
|
200 | + if (! empty($post_id) ) { |
|
201 | + if ('public' === $post_visibility ) { |
|
202 | + if (! in_array($post_id, $public_posts) ) { |
|
203 | + array_push($public_posts, $post_id); |
|
204 | + } |
|
205 | + } |
|
206 | + if ('private' === $post_visibility ) { |
|
207 | + unset($public_posts[ array_search($post_id, $public_posts) ]); |
|
208 | + } |
|
209 | + } |
|
210 | + } |
|
211 | + |
|
212 | + if (! empty($post_id) ) { |
|
213 | + $posts_implode = implode(", ", $public_posts); |
|
214 | + |
|
215 | + if ('inherit' !== get_post_status($post_id) ) { |
|
216 | + |
|
217 | + if (true === $is_valid_visibility_nonce ) { |
|
218 | + update_option('subway_public_post', $posts_implode); |
|
219 | + update_post_meta( |
|
220 | + $post_id, |
|
221 | + self::VISIBILITY_METAKEY, |
|
222 | + $post_visibility |
|
223 | + ); |
|
224 | + } |
|
225 | + |
|
226 | + } |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * This method runs the methods that handles the update for a post_meta. |
|
232 | + * |
|
233 | + * @param integer $post_id Contains ID of the current post. |
|
234 | + * |
|
235 | + * @since 2.0.9 |
|
236 | + * @access public |
|
237 | + * @return boolean false Returns false if nonce is not valid. |
|
238 | + */ |
|
239 | + public function saveMetaboxValues( $post_id ) |
|
240 | + { |
|
241 | + $this->saveVisibilityMetabox($post_id); |
|
242 | + return; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * Initialize metabox arguments. |
|
247 | + * |
|
248 | + * @param array $args The arguments for the get_post_types(). |
|
249 | + * @param string $output Your desired output for the data. |
|
250 | + * |
|
251 | + * @since 2.0.9 |
|
252 | + * @access public |
|
253 | + * @return void |
|
254 | + */ |
|
255 | + public static function getPostTypes( $args = '', $output = '' ) |
|
256 | + { |
|
257 | + if (empty($args) ) { |
|
258 | + $args = array( |
|
259 | + 'public' => true, |
|
260 | + ); |
|
261 | + $output = 'names'; |
|
262 | + } |
|
263 | + |
|
264 | + $post_types = get_post_types($args, $output); |
|
265 | + |
|
266 | + return $post_types; |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * This method verify if nonce is valid. |
|
271 | + * |
|
272 | + * @param mixed $nonce the name of a metabox nonce. |
|
273 | + * |
|
274 | + * @since 2.0.9 |
|
275 | + * @access public |
|
276 | + * @return boolean true Returns true if nonce is valid. |
|
277 | + */ |
|
278 | + public function isNonceValid( $nonce ) |
|
279 | + { |
|
280 | + if (!isset($nonce) || !wp_verify_nonce($nonce, basename(__FILE__)) ) { |
|
281 | + return; |
|
282 | + } |
|
283 | + |
|
284 | + return true; |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * Checks if a post is set to private. |
|
289 | + * |
|
290 | + * @param integer $post_id Contains ID of the current post. |
|
291 | + * |
|
292 | + * @since 2.0.9 |
|
293 | + * @access public |
|
294 | + * @return boolean true Returns true if post is private. Otherwise false. |
|
295 | + */ |
|
296 | + public static function isPostPrivate( $post_id ) |
|
297 | + { |
|
298 | + $meta_value = ''; |
|
299 | + |
|
300 | + if ( ! empty( $post_id ) ) { |
|
301 | + $meta_value = get_post_meta($post_id, self::VISIBILITY_METAKEY, true); |
|
302 | + |
|
303 | + // New page or old pages that don't have Subway'\ Visibility Options |
|
304 | + if ( empty ( $meta_value ) ) { |
|
305 | + // Get the value from the general settings (Settings > Subway) |
|
306 | + $is_site_public = Options::isPublicSite(); |
|
307 | + if ( ! $is_site_public ) { |
|
308 | + // It's private. |
|
309 | + return true; |
|
310 | + } |
|
311 | + } |
|
312 | + if ('private' === $meta_value ) { |
|
313 | + return true; |
|
314 | + } |
|
315 | + } |
|
316 | + |
|
317 | + return false; |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * Checks if a post is set to public. |
|
322 | + * |
|
323 | + * @param integer $post_id Contains ID of the current post. |
|
324 | + * |
|
325 | + * @since 2.0.9 |
|
326 | + * @access public |
|
327 | + * @return boolean true Returns true if post is public. Otherwise false. |
|
328 | + */ |
|
329 | + public static function isPostPublic( $post_id ) |
|
330 | + { |
|
331 | + $public_post = Options::getPublicPostsIdentifiers(); |
|
332 | + |
|
333 | + if (! empty($post_id) ) { |
|
334 | + if (! in_array($post_id, $public_post, true) ) { |
|
335 | + return true; |
|
336 | + } |
|
337 | + } |
|
338 | + |
|
339 | + return false; |
|
340 | + } |
|
341 | 341 | |
342 | 342 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | namespace Subway; |
21 | 21 | |
22 | 22 | if (! defined('ABSPATH') ) { |
23 | - return; |
|
23 | + return; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -36,185 +36,185 @@ discard block |
||
36 | 36 | final class AuthRedirect |
37 | 37 | { |
38 | 38 | |
39 | - /** |
|
40 | - * Handles our ajax authentication. |
|
41 | - * |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public static function handleAuthentication() |
|
45 | - { |
|
39 | + /** |
|
40 | + * Handles our ajax authentication. |
|
41 | + * |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public static function handleAuthentication() |
|
45 | + { |
|
46 | 46 | |
47 | - // Set the header type to json. |
|
48 | - header('Content-Type: application/json'); |
|
47 | + // Set the header type to json. |
|
48 | + header('Content-Type: application/json'); |
|
49 | 49 | |
50 | - $is_signin = new \WP_Error( 'broke', __( 'Unable to authenticate user', "subway" ) ); |
|
50 | + $is_signin = new \WP_Error( 'broke', __( 'Unable to authenticate user', "subway" ) ); |
|
51 | 51 | |
52 | - $log = filter_input(INPUT_POST, 'log', FILTER_SANITIZE_STRING); |
|
52 | + $log = filter_input(INPUT_POST, 'log', FILTER_SANITIZE_STRING); |
|
53 | 53 | |
54 | - $pwd = filter_input(INPUT_POST, 'pwd', FILTER_SANITIZE_STRING); |
|
54 | + $pwd = filter_input(INPUT_POST, 'pwd', FILTER_SANITIZE_STRING); |
|
55 | 55 | |
56 | - if (empty($log) && empty($pwd) ) { |
|
56 | + if (empty($log) && empty($pwd) ) { |
|
57 | 57 | |
58 | - $response['type'] = 'error'; |
|
58 | + $response['type'] = 'error'; |
|
59 | 59 | |
60 | - $response['message'] = esc_html__( |
|
61 | - 'Username and Password cannot be empty.', |
|
62 | - 'subway' |
|
63 | - ); |
|
60 | + $response['message'] = esc_html__( |
|
61 | + 'Username and Password cannot be empty.', |
|
62 | + 'subway' |
|
63 | + ); |
|
64 | 64 | |
65 | - } else { |
|
65 | + } else { |
|
66 | 66 | |
67 | - $is_signin = wp_signon(); |
|
67 | + $is_signin = wp_signon(); |
|
68 | 68 | |
69 | - $response = array(); |
|
69 | + $response = array(); |
|
70 | 70 | |
71 | - if (is_wp_error($is_signin) ) { |
|
71 | + if (is_wp_error($is_signin) ) { |
|
72 | 72 | |
73 | - $response['type'] = 'error'; |
|
73 | + $response['type'] = 'error'; |
|
74 | 74 | |
75 | - $response['message'] = $is_signin->get_error_message(); |
|
75 | + $response['message'] = $is_signin->get_error_message(); |
|
76 | 76 | |
77 | - } else { |
|
77 | + } else { |
|
78 | 78 | |
79 | - $response['type'] = 'success'; |
|
79 | + $response['type'] = 'success'; |
|
80 | 80 | |
81 | - $response['message'] = esc_html__( |
|
82 | - 'You have successfully logged-in. Redirecting you in few seconds...', |
|
83 | - 'subway' |
|
84 | - ); |
|
81 | + $response['message'] = esc_html__( |
|
82 | + 'You have successfully logged-in. Redirecting you in few seconds...', |
|
83 | + 'subway' |
|
84 | + ); |
|
85 | 85 | |
86 | - } |
|
87 | - } |
|
86 | + } |
|
87 | + } |
|
88 | 88 | |
89 | - $subway_redirect_url = AuthRedirect::getLoginRedirectUrl('', $is_signin); |
|
89 | + $subway_redirect_url = AuthRedirect::getLoginRedirectUrl('', $is_signin); |
|
90 | 90 | |
91 | - $response['redirect_url'] = apply_filters( |
|
92 | - 'subway_login_redirect', |
|
93 | - $subway_redirect_url, |
|
94 | - $is_signin |
|
95 | - ); |
|
91 | + $response['redirect_url'] = apply_filters( |
|
92 | + 'subway_login_redirect', |
|
93 | + $subway_redirect_url, |
|
94 | + $is_signin |
|
95 | + ); |
|
96 | 96 | |
97 | - echo wp_json_encode($response); |
|
97 | + echo wp_json_encode($response); |
|
98 | 98 | |
99 | - wp_die(); |
|
99 | + wp_die(); |
|
100 | 100 | |
101 | - } |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Returns the filtered redirect url for the current user. |
|
105 | - * |
|
106 | - * @param string $redirect_to The default redirect callback argument. |
|
107 | - * @param mixed $user This holds the meta info of currently logged-in user. |
|
108 | - * |
|
109 | - * @return string The final redirect url. |
|
110 | - */ |
|
111 | - public static function getLoginRedirectUrl( $redirect_to, $user ) |
|
112 | - { |
|
103 | + /** |
|
104 | + * Returns the filtered redirect url for the current user. |
|
105 | + * |
|
106 | + * @param string $redirect_to The default redirect callback argument. |
|
107 | + * @param mixed $user This holds the meta info of currently logged-in user. |
|
108 | + * |
|
109 | + * @return string The final redirect url. |
|
110 | + */ |
|
111 | + public static function getLoginRedirectUrl( $redirect_to, $user ) |
|
112 | + { |
|
113 | 113 | |
114 | - $subway_redirect_type = get_option('subway_redirect_type'); |
|
114 | + $subway_redirect_type = get_option('subway_redirect_type'); |
|
115 | 115 | |
116 | - // Redirect the user to default behaviour. |
|
117 | - // If there are no redirect type option saved. |
|
118 | - if (empty($subway_redirect_type) ) { |
|
116 | + // Redirect the user to default behaviour. |
|
117 | + // If there are no redirect type option saved. |
|
118 | + if (empty($subway_redirect_type) ) { |
|
119 | 119 | |
120 | - return $redirect_to; |
|
120 | + return $redirect_to; |
|
121 | 121 | |
122 | - } |
|
122 | + } |
|
123 | 123 | |
124 | - if ('default' === $subway_redirect_type ) { |
|
125 | - return $redirect_to; |
|
126 | - } |
|
124 | + if ('default' === $subway_redirect_type ) { |
|
125 | + return $redirect_to; |
|
126 | + } |
|
127 | 127 | |
128 | - if ('page' === $subway_redirect_type ) { |
|
128 | + if ('page' === $subway_redirect_type ) { |
|
129 | 129 | |
130 | - // Get the page url of the selected page. |
|
131 | - // If the admin selected 'Custom Page' in the redirect type settings. |
|
132 | - $selected_redirect_page = intval(get_option('subway_redirect_page_id')); |
|
130 | + // Get the page url of the selected page. |
|
131 | + // If the admin selected 'Custom Page' in the redirect type settings. |
|
132 | + $selected_redirect_page = intval(get_option('subway_redirect_page_id')); |
|
133 | 133 | |
134 | - // Redirect to default WordPress behaviour. |
|
135 | - // If the user did not select page. |
|
136 | - if (empty($selected_redirect_page) ) { |
|
134 | + // Redirect to default WordPress behaviour. |
|
135 | + // If the user did not select page. |
|
136 | + if (empty($selected_redirect_page) ) { |
|
137 | 137 | |
138 | - return $redirect_to; |
|
139 | - } |
|
138 | + return $redirect_to; |
|
139 | + } |
|
140 | 140 | |
141 | - // Otherwise, get the permalink of the saved page |
|
142 | - // and let the user go into that page. |
|
143 | - return get_permalink($selected_redirect_page); |
|
141 | + // Otherwise, get the permalink of the saved page |
|
142 | + // and let the user go into that page. |
|
143 | + return get_permalink($selected_redirect_page); |
|
144 | 144 | |
145 | - } elseif ('custom_url' === $subway_redirect_type ) { |
|
145 | + } elseif ('custom_url' === $subway_redirect_type ) { |
|
146 | 146 | |
147 | - // Get the custom url saved in the redirect type settings. |
|
148 | - $entered_custom_url = get_option('subway_redirect_custom_url'); |
|
147 | + // Get the custom url saved in the redirect type settings. |
|
148 | + $entered_custom_url = get_option('subway_redirect_custom_url'); |
|
149 | 149 | |
150 | - // Redirect to default WordPress behaviour |
|
151 | - // if the user did enter a custom url. |
|
152 | - if (empty($entered_custom_url) ) { |
|
150 | + // Redirect to default WordPress behaviour |
|
151 | + // if the user did enter a custom url. |
|
152 | + if (empty($entered_custom_url) ) { |
|
153 | 153 | |
154 | - return $redirect_to; |
|
154 | + return $redirect_to; |
|
155 | 155 | |
156 | - } |
|
156 | + } |
|
157 | 157 | |
158 | - // Otherwise, get the custom url saved |
|
159 | - // and let the user go into that page. |
|
160 | - if (! empty($user->ID) ) { |
|
161 | - $entered_custom_url = str_replace( |
|
162 | - '%user_id%', $user->ID, |
|
163 | - $entered_custom_url |
|
164 | - ); |
|
165 | - } |
|
158 | + // Otherwise, get the custom url saved |
|
159 | + // and let the user go into that page. |
|
160 | + if (! empty($user->ID) ) { |
|
161 | + $entered_custom_url = str_replace( |
|
162 | + '%user_id%', $user->ID, |
|
163 | + $entered_custom_url |
|
164 | + ); |
|
165 | + } |
|
166 | 166 | |
167 | - if (! empty($user->user_login) ) { |
|
168 | - $entered_custom_url = str_replace( |
|
169 | - '%user_name%', $user->user_login, |
|
170 | - $entered_custom_url |
|
171 | - ); |
|
172 | - } |
|
167 | + if (! empty($user->user_login) ) { |
|
168 | + $entered_custom_url = str_replace( |
|
169 | + '%user_name%', $user->user_login, |
|
170 | + $entered_custom_url |
|
171 | + ); |
|
172 | + } |
|
173 | 173 | |
174 | - return $entered_custom_url; |
|
174 | + return $entered_custom_url; |
|
175 | 175 | |
176 | - } |
|
176 | + } |
|
177 | 177 | |
178 | - // Otherwise, quit and redirect the user back to default WordPress behaviour. |
|
179 | - return $redirect_to; |
|
180 | - } |
|
178 | + // Otherwise, quit and redirect the user back to default WordPress behaviour. |
|
179 | + return $redirect_to; |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * Callback function for the 'login_url' filter defined in Subway.php |
|
184 | - * |
|
185 | - * @param string $login_url The login url. |
|
186 | - * |
|
187 | - * @return string The final login url. |
|
188 | - */ |
|
189 | - public static function loginUrl( $login_url ) |
|
190 | - { |
|
182 | + /** |
|
183 | + * Callback function for the 'login_url' filter defined in Subway.php |
|
184 | + * |
|
185 | + * @param string $login_url The login url. |
|
186 | + * |
|
187 | + * @return string The final login url. |
|
188 | + */ |
|
189 | + public static function loginUrl( $login_url ) |
|
190 | + { |
|
191 | 191 | |
192 | - $subway_login_page = Options::getRedirectPageUrl(); |
|
192 | + $subway_login_page = Options::getRedirectPageUrl(); |
|
193 | 193 | |
194 | - // Return the default login url if there is no log-in page defined. |
|
195 | - if (empty($subway_login_page) ) { |
|
196 | - return $login_url; |
|
197 | - } |
|
194 | + // Return the default login url if there is no log-in page defined. |
|
195 | + if (empty($subway_login_page) ) { |
|
196 | + return $login_url; |
|
197 | + } |
|
198 | 198 | |
199 | - // Otherwise, return the Subway login page. |
|
200 | - return $subway_login_page; |
|
199 | + // Otherwise, return the Subway login page. |
|
200 | + return $subway_login_page; |
|
201 | 201 | |
202 | - } |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * The callback function for our logout filter. |
|
206 | - * |
|
207 | - * @return void |
|
208 | - */ |
|
209 | - public static function logoutUrl() |
|
210 | - { |
|
204 | + /** |
|
205 | + * The callback function for our logout filter. |
|
206 | + * |
|
207 | + * @return void |
|
208 | + */ |
|
209 | + public static function logoutUrl() |
|
210 | + { |
|
211 | 211 | |
212 | - $subway_login_page = Options::getRedirectPageUrl(); |
|
212 | + $subway_login_page = Options::getRedirectPageUrl(); |
|
213 | 213 | |
214 | - wp_safe_redirect(esc_url($subway_login_page . '?loggedout=true')); |
|
214 | + wp_safe_redirect(esc_url($subway_login_page . '?loggedout=true')); |
|
215 | 215 | |
216 | - Helpers::close(); |
|
216 | + Helpers::close(); |
|
217 | 217 | |
218 | - } |
|
218 | + } |
|
219 | 219 | |
220 | 220 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | namespace Subway; |
21 | 21 | |
22 | 22 | if (! defined('ABSPATH') ) { |
23 | - return; |
|
23 | + return; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -36,120 +36,120 @@ discard block |
||
36 | 36 | final class PageRedirect |
37 | 37 | { |
38 | 38 | |
39 | - /** |
|
40 | - * Redirects pages into our login page. |
|
41 | - * |
|
42 | - * @return void. |
|
43 | - */ |
|
44 | - public static function index() |
|
45 | - { |
|
46 | - |
|
47 | - // Additional filter for custom pages, taxonomy, links, parameterized urls, etc. |
|
48 | - // Callback function/method must return true (boolean) to disable redirect. |
|
49 | - $should_exit = apply_filters( 'subway/classes/subway-page-redirect/index/before-page-redirect', false ); |
|
50 | - |
|
51 | - if ( $should_exit ) { |
|
52 | - return; |
|
53 | - } |
|
54 | - |
|
55 | - // Only execute for non logged in users. |
|
56 | - if (is_user_logged_in() ) { |
|
57 | - return; |
|
58 | - } |
|
39 | + /** |
|
40 | + * Redirects pages into our login page. |
|
41 | + * |
|
42 | + * @return void. |
|
43 | + */ |
|
44 | + public static function index() |
|
45 | + { |
|
46 | + |
|
47 | + // Additional filter for custom pages, taxonomy, links, parameterized urls, etc. |
|
48 | + // Callback function/method must return true (boolean) to disable redirect. |
|
49 | + $should_exit = apply_filters( 'subway/classes/subway-page-redirect/index/before-page-redirect', false ); |
|
50 | + |
|
51 | + if ( $should_exit ) { |
|
52 | + return; |
|
53 | + } |
|
54 | + |
|
55 | + // Only execute for non logged in users. |
|
56 | + if (is_user_logged_in() ) { |
|
57 | + return; |
|
58 | + } |
|
59 | 59 | |
60 | - $is_private = false; |
|
60 | + $is_private = false; |
|
61 | 61 | |
62 | - $queried_id = get_queried_object_id(); |
|
62 | + $queried_id = get_queried_object_id(); |
|
63 | 63 | |
64 | - $current_post = get_post(absint($queried_id)); |
|
64 | + $current_post = get_post(absint($queried_id)); |
|
65 | 65 | |
66 | - $login_page_id = absint(get_option('subway_login_page')); |
|
66 | + $login_page_id = absint(get_option('subway_login_page')); |
|
67 | 67 | |
68 | - $excluded_page = Options::getPublicPostsIdentifiers(); |
|
68 | + $excluded_page = Options::getPublicPostsIdentifiers(); |
|
69 | 69 | |
70 | - // Already escaped inside 'subway_get_redirect_page_url'. |
|
71 | - $redirect_page = Options::getRedirectPageUrl(); // WPCS XSS OK. |
|
70 | + // Already escaped inside 'subway_get_redirect_page_url'. |
|
71 | + $redirect_page = Options::getRedirectPageUrl(); // WPCS XSS OK. |
|
72 | 72 | |
73 | - if ( !empty( $current_post ) ) { |
|
73 | + if ( !empty( $current_post ) ) { |
|
74 | 74 | $is_private = Metabox::isPostPrivate( $current_post->ID ); |
75 | - } |
|
76 | - |
|
77 | - // do_action( 'subway/classes/subway-page-redirect/index/before_page_redirect' ); |
|
78 | - |
|
79 | - // Turn off if is in 'wc-ajax' (woocommerce) |
|
80 | - if ( function_exists( 'is_ajax') ) { |
|
81 | - if ( is_ajax() ) { |
|
82 | - return; |
|
83 | - } |
|
84 | - } |
|
85 | - |
|
86 | - // Same for normal ajax requests. |
|
87 | - if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
88 | - return; |
|
89 | - } |
|
90 | - |
|
91 | - // Exit if site is public. |
|
92 | - if ( Options::isPublicSite() ) { |
|
93 | - return; |
|
94 | - } |
|
95 | - |
|
96 | - // Check if redirect page is empty or not. |
|
97 | - if ( empty( $redirect_page ) ) { |
|
98 | - return; |
|
99 | - } |
|
100 | - |
|
101 | - // Check if buddypress activate page. |
|
102 | - if (function_exists('bp_is_activation_page') ) { |
|
103 | - if (bp_is_activation_page() ) { |
|
104 | - return; |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - // Check if buddypress registration page. |
|
109 | - if (function_exists('bp_is_register_page') ) { |
|
110 | - if (bp_is_register_page() ) { |
|
111 | - return; |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - // Assign 0 value to empty $post->ID to prevent exception. |
|
116 | - // This applies to custom WordPress pages such as BP Members Page and Groups. |
|
117 | - if (empty($current_post) ) { |
|
118 | - $current_post = new \stdclass; |
|
119 | - $current_post->ID = 0; |
|
120 | - } |
|
121 | - |
|
122 | - $current_page_id = absint($current_post->ID); |
|
123 | - |
|
124 | - // Check if $current_page_id && $selected_blog_id is equal to each other. |
|
125 | - // Get the page ID instead of global $post->ID that the query returns. |
|
126 | - // The ID of the first post object inside the loop is not correct. |
|
127 | - $blog_id = absint(get_option('page_for_posts')); |
|
128 | - |
|
129 | - if (is_home() ) { |
|
130 | - if ($blog_id === $login_page_id ) { |
|
131 | - $current_page_id = $blog_id; |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - // Only execute the script for non-loggedin visitors. |
|
136 | - if ( ! is_user_logged_in() ) { |
|
137 | - |
|
138 | - if ($current_page_id !== $login_page_id ) { |
|
139 | - |
|
140 | - if ( ! in_array( $current_page_id, $excluded_page, true ) || in_array( $current_page_id, $excluded_page, true ) && true === $is_private ) { |
|
141 | - |
|
142 | - wp_safe_redirect( |
|
143 | - add_query_arg( |
|
144 | - array( '_redirected' => 'yes' ), |
|
145 | - $redirect_page |
|
146 | - ) |
|
147 | - ); |
|
148 | - |
|
149 | - Helpers::close(); |
|
150 | - } |
|
151 | - } |
|
152 | - } |
|
153 | - } |
|
75 | + } |
|
76 | + |
|
77 | + // do_action( 'subway/classes/subway-page-redirect/index/before_page_redirect' ); |
|
78 | + |
|
79 | + // Turn off if is in 'wc-ajax' (woocommerce) |
|
80 | + if ( function_exists( 'is_ajax') ) { |
|
81 | + if ( is_ajax() ) { |
|
82 | + return; |
|
83 | + } |
|
84 | + } |
|
85 | + |
|
86 | + // Same for normal ajax requests. |
|
87 | + if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
88 | + return; |
|
89 | + } |
|
90 | + |
|
91 | + // Exit if site is public. |
|
92 | + if ( Options::isPublicSite() ) { |
|
93 | + return; |
|
94 | + } |
|
95 | + |
|
96 | + // Check if redirect page is empty or not. |
|
97 | + if ( empty( $redirect_page ) ) { |
|
98 | + return; |
|
99 | + } |
|
100 | + |
|
101 | + // Check if buddypress activate page. |
|
102 | + if (function_exists('bp_is_activation_page') ) { |
|
103 | + if (bp_is_activation_page() ) { |
|
104 | + return; |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + // Check if buddypress registration page. |
|
109 | + if (function_exists('bp_is_register_page') ) { |
|
110 | + if (bp_is_register_page() ) { |
|
111 | + return; |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + // Assign 0 value to empty $post->ID to prevent exception. |
|
116 | + // This applies to custom WordPress pages such as BP Members Page and Groups. |
|
117 | + if (empty($current_post) ) { |
|
118 | + $current_post = new \stdclass; |
|
119 | + $current_post->ID = 0; |
|
120 | + } |
|
121 | + |
|
122 | + $current_page_id = absint($current_post->ID); |
|
123 | + |
|
124 | + // Check if $current_page_id && $selected_blog_id is equal to each other. |
|
125 | + // Get the page ID instead of global $post->ID that the query returns. |
|
126 | + // The ID of the first post object inside the loop is not correct. |
|
127 | + $blog_id = absint(get_option('page_for_posts')); |
|
128 | + |
|
129 | + if (is_home() ) { |
|
130 | + if ($blog_id === $login_page_id ) { |
|
131 | + $current_page_id = $blog_id; |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + // Only execute the script for non-loggedin visitors. |
|
136 | + if ( ! is_user_logged_in() ) { |
|
137 | + |
|
138 | + if ($current_page_id !== $login_page_id ) { |
|
139 | + |
|
140 | + if ( ! in_array( $current_page_id, $excluded_page, true ) || in_array( $current_page_id, $excluded_page, true ) && true === $is_private ) { |
|
141 | + |
|
142 | + wp_safe_redirect( |
|
143 | + add_query_arg( |
|
144 | + array( '_redirected' => 'yes' ), |
|
145 | + $redirect_page |
|
146 | + ) |
|
147 | + ); |
|
148 | + |
|
149 | + Helpers::close(); |
|
150 | + } |
|
151 | + } |
|
152 | + } |
|
153 | + } |
|
154 | 154 | |
155 | 155 | } |