PluginProbe ʕ •ᴥ•ʔ
Easy HTTPS Redirection (SSL) / 2.0.0
Easy HTTPS Redirection (SSL) v2.0.0
trunk 1.5 1.6 1.8 1.9.1 1.9.2 2.0.0 2.0.1
https-redirection / admin / ehssl-settings-menu.php
https-redirection / admin Last commit date
ehssl-admin-init.php 1 year ago ehssl-admin-menu.php 1 year ago ehssl-certificate-expiry-menu.php 1 year ago ehssl-dashboard-menu.php 1 year ago ehssl-settings-menu-old.php 1 year ago ehssl-settings-menu.php 1 year ago ehssl-ssl-management-menu.php 1 year ago index.php 1 year ago
ehssl-settings-menu.php
351 lines
1 <?php
2
3 class EHSSL_Settings_Menu extends EHSSL_Admin_Menu
4 {
5 public $menu_page_slug = EHSSL_SETTINGS_MENU_SLUG;
6
7 // Specify all the tabs of this menu in the following array.
8 public $dashboard_menu_tabs = array('general' => 'General', 'mixed-contents' => 'Mixed Contents');
9
10 public function __construct()
11 {
12 $this->render_menu_page();
13 }
14
15 public function get_current_tab()
16 {
17 $tab = isset($_GET['tab']) ? $_GET['tab'] : array_keys($this->dashboard_menu_tabs)[0];
18 return $tab;
19 }
20
21 /**
22 * Renders our tabs of this menu as nav items
23 */
24 public function render_page_tabs()
25 {
26 $current_tab = $this->get_current_tab();
27 foreach ($this->dashboard_menu_tabs as $tab_key => $tab_caption) {
28 $active = $current_tab == $tab_key ? 'nav-tab-active' : '';
29 echo '<a class="nav-tab ' . $active . '" href="?page=' . $this->menu_page_slug . '&tab=' . $tab_key . '">' . $tab_caption . '</a>';
30 }
31 }
32
33 /**
34 * The menu rendering goes here
35 */
36 public function render_menu_page()
37 {
38 $tab = $this->get_current_tab();
39
40 ?>
41 <div class="wrap">
42 <h2><?php _e("Settings", 'https-redirection')?></h2>
43 <h2 class="nav-tab-wrapper"><?php $this->render_page_tabs();?></h2>
44 <div id="poststuff"><div id="post-body">
45 <?php
46
47 switch ($tab) {
48 case 'mixed-contents':
49 //include_once('file-to-handle-this-tab-rendering.php');//If you want to include a file
50 $this->render_mixed_content_tab();
51 break;
52 case 'general':
53 default:
54 //include_once('file-to-handle-this-tab-rendering.php');//If you want to include a file
55 $this->render_general_tab();
56 break;
57 }
58 ?>
59 </div>
60 </div>
61 <?php $this->documentation_link_box();?>
62 </div><!-- end or wrap -->
63 <?php
64 }
65
66 public function render_general_tab()
67 {
68 $settings = get_option('httpsrdrctn_options', array());
69
70 // Save data for settings page.
71 if (isset($_REQUEST['httpsrdrctn_form_submit']) && check_admin_referer(plugin_basename(__FILE__), 'httpsrdrctn_nonce_name')) {
72 $settings['https'] = isset($_REQUEST['httpsrdrctn_https']) ? $_REQUEST['httpsrdrctn_https'] : 0;
73 $settings['https_domain'] = isset($_REQUEST['httpsrdrctn_https_domain']) ? $_REQUEST['httpsrdrctn_https_domain'] : 0;
74
75 if (isset($_REQUEST['httpsrdrctn_https_pages_array'])) {
76 $settings['https_pages_array'] = array();
77 // var_dump($httpsrdrctn_options['https_pages_array']);
78 foreach ($_REQUEST['httpsrdrctn_https_pages_array'] as $httpsrdrctn_https_page) {
79 if (!empty($httpsrdrctn_https_page) && $httpsrdrctn_https_page != '') {
80 $httpsrdrctn_https_page = str_replace('https', 'http', $httpsrdrctn_https_page);
81 $settings['https_pages_array'][] = trim(str_replace(home_url(), '', $httpsrdrctn_https_page), '/');
82 }
83 }
84 }
85
86 // Update options in the database.
87 update_option('httpsrdrctn_options', $settings, '', 'yes');
88
89 echo '<div class="notice notice-success"><p>'.__("Settings Saved.", 'https-redirection').'</p></div>';
90
91 $httpsrdrctn_obj = new EHSSL_Htaccess();
92 $httpsrdrctn_obj->write_to_htaccess();
93
94 // clear caching plugins cache if needed
95 // WP Fastest Cache
96 if (isset($GLOBALS["wp_fastest_cache"])) {
97 $wpfc = $GLOBALS["wp_fastest_cache"];
98 if (method_exists($wpfc, 'deleteCache') && is_callable(array($wpfc, 'deleteCache'))) {
99 $wpfc->deleteCache(true);
100 }
101 }
102 // httpsrdrctn_generate_htaccess();
103
104 }
105 $siteSSLurl = get_home_url(null, '', 'https');
106
107 // Save data for settings page.
108 if (isset($_POST['ehssl_debug_log_form_submit']) && check_admin_referer('ehssl_debug_settings_nonce')) {
109 $settings['enable_debug_logging'] = isset($_POST['enable_debug_logging']) ? esc_attr($_POST['enable_debug_logging']) : 0;
110
111 update_option('httpsrdrctn_options', $settings)
112
113 ?>
114 <div class="notice notice-success">
115 <p><?php _e("Settings Saved.", 'https-redirection');?></p>
116 </div>
117 <?php
118 }
119
120 $is_debug_logging_enabled = isset($settings['enable_debug_logging']) ? esc_attr($settings['enable_debug_logging']) : 0;
121
122 ?>
123 <div class="ehssl-yellow-box">
124 <p>
125 <?php echo sprintf(__("When you enable the HTTPS redirection, the plugin will force redirect the URL to the HTTPS version of the URL. So before enabling this plugin's feature, visit your site's HTTPS URL %s to make sure the page loads correctly. Otherwise you may get locked out if your SSL certificate is not installed correctly on your site or the HTTPS URL is not working and this plugin is auto redirecting to the HTTPS URL.", 'https-redirection'), '<a href="' . $siteSSLurl . '" target="_blank">' . $siteSSLurl . '</a>'); ?>
126 </p>
127 <p>
128 <span style="font-weight:bold; color:red;"><?php _e('Important!', 'https-redirection');?></span>
129 <?php _e("If you're using caching plugins similar to W3 Total Cache or WP Super Cache, you need to clear their cache after you enable or disable automatic redirection option. Failing to do so may result in mixed content warning from browser.", 'https-redirection');?>
130 </p>
131 </div>
132 <div class="postbox">
133 <h3 class="hndle"><label for="title"><?php _e("HTTPS Redirection", 'https-redirection');?></label></h3>
134 <div class="inside">
135 <?php
136 // Display form on the setting page.
137 if (get_option('permalink_structure')) {
138 // Pretty permalink is enabled. So allow HTTPS redirection feature.
139 ?>
140 <div id="httpsrdrctn_settings_notice" class="updated fade" style="display:none">
141 <p>
142 <strong><?php _e("Notice:", 'https-redirection');?></strong><?php _e("The plugin's settings have been changed. In order to save them please don't forget to click the 'Save Changes' button.", 'https-redirection');?>
143 </p>
144 </div>
145
146 <form id="httpsrdrctn_settings_form" method="post" action="">
147 <div style="position: relative">
148 <table class="form-table">
149 <tr valign="top">
150 <th scope="row"><?php _e('Enable Automatic Redirection to HTTPS', 'https-redirection');?></th>
151 <td>
152 <label>
153 <input type="checkbox" id="httpsrdrctn-checkbox" name="httpsrdrctn_https" value="1" <?php if ('1' == $settings['https']) {echo "checked=\"checked\" ";}?> />
154 </label>
155 <br />
156 <p class="description"><?php _e("Use this option to make your webpage(s) load in HTTPS version only. If someone enters a non-https URL in the browser's address bar then the plugin will automatically redirect to the HTTPS version of that URL.", 'https-redirection');?></p>
157 </td>
158 </tr>
159 </table>
160
161 <div class="ehssl-enable-automatic-redirection httpsrdrctn-overlay <?php echo (is_ssl() ? 'hidden' : ''); ?>"></div>
162 </div>
163
164 <div style="position: relative">
165 <table class="form-table">
166 <tr>
167 <th scope="row"><?php _e('Apply HTTPS Redirection To:', 'https-redirection');?></th>
168 <td>
169 <div style="margin-bottom: 6px">
170 <label><input type="radio" name="httpsrdrctn_https_domain" value="1" <?php if ('1' == $settings['https_domain']) {echo "checked=\"checked\" ";}?> /> <?php _e('The whole domain', 'https-redirection');?></label>
171 </div>
172 <div style="margin-bottom: 6px">
173 <label><input type="radio" name="httpsrdrctn_https_domain" value="0" <?php if ('0' == $settings['https_domain']) {echo "checked=\"checked\" ";}?> /> <?php _e('A few pages', 'https-redirection');?></label>
174 </div>
175 <?php foreach ($settings['https_pages_array'] as $https_page) { ?>
176 <div style="margin-bottom: 5px">
177 <?php echo str_replace("http://", "https://", home_url()); ?>/<input type="text" name="httpsrdrctn_https_pages_array[]" value="<?php echo $https_page; ?>" /> <span class="button-secondary rewrite_item_delete_btn"><i class="dashicons dashicons-trash"></i></span> <span class="rewrite_item_blank_error"><?php _e('Please enter a page slug value in the field before adding it.', 'https-redirection');?></span>
178 </div>
179 <?php } ?>
180 <div class="rewrite_new_item">
181 <?php echo str_replace("http://", "https://", home_url()); ?>/<input type="text" name="httpsrdrctn_https_pages_array[]" placeholder="<?php _e('Enter the page slug','https-redirection'); ?>" value="" /> <span class="button-secondary rewrite_item_add_btn"><i class="dashicons dashicons-plus-alt2"></i></span> <span class="rewrite_item_blank_error"><?php _e('Please enter a page slug value in the field before adding it.', 'https-redirection');?></span>
182 </div>
183 </td>
184 </tr>
185 </table>
186
187 <div class="ehssl-apply-redirection-on httpsrdrctn-overlay <?php echo ($settings['https'] == 1 ? 'hidden' : ''); ?>"></div>
188 </div>
189
190 <input type="hidden" name="httpsrdrctn_form_submit" value="submit" />
191
192 <p class="submit">
193 <input type="submit" class="button-primary" value="<?php _e('Save Changes')?>" <?php echo !is_ssl() ? 'disabled' : '' ?>/>
194 </p>
195 <?php wp_nonce_field(plugin_basename(__FILE__), 'httpsrdrctn_nonce_name');?>
196 </form>
197 <script>
198 jQuery('input#httpsrdrctn-checkbox').change(function() {
199 if (jQuery(this).is(':checked')) {
200 jQuery('div.ehssl-apply-redirection-on.httpsrdrctn-overlay').fadeOut('fast');
201 } else {
202 jQuery('div.ehssl-apply-redirection-on.httpsrdrctn-overlay').fadeIn('fast');
203 }
204 });
205 </script>
206 <style>
207 .httpsrdrctn-overlay {
208 position: absolute;
209 top: 10px;
210 background-color: white;
211 width: 100%;
212 height: 100%;
213 opacity: 0.5;
214 text-align: center;
215 }
216 </style>
217
218 <div class="ehssl-red-box">
219 <p><strong><?php _e("Notice:", 'https-redirection');?></strong> <?php _e("It is very important to be extremely attentive when making changes to .htaccess file.", 'https-redirection');?></p>
220 <p><?php _e('If after making changes your site stops functioning, do the following:', 'https-redirection');?></p>
221 <p><?php _e('Step #1: Open .htaccess file in the root directory of the WordPress install and delete everything between the following two lines', 'https-redirection');?></p>
222 <p style="border: 1px solid #ccc; padding: 10px;">
223 # BEGIN HTTPS Redirection Plugin<br />
224 # END HTTPS Redirection Plugin
225 </p>
226 <p><?php _e('Step #2: Save the htaccess file (this will erase any change this plugin made to that file).', 'https-redirection');?></p>
227 <p><?php _e("Step #3: Deactivate the plugin or rename this plugin's folder (which will deactivate the plugin).", 'https-redirection');?></p>
228
229 <p><?php _e('The changes will be applied immediately after saving the changes, if you are not sure - do not click the "Save changes" button.', 'https-redirection');?></p>
230 </div>
231
232 <?php } else {?>
233 <!-- pretty permalink is NOT enabled. This plugin can't work. -->
234 <div class="error">
235 <p><?php _e('HTTPS redirection only works if you have pretty permalinks enabled.', 'https-redirection');?></p>
236 <p><?php _e('To enable pretty permalinks go to <em>Settings > Permalinks</em> and select any option other than "default".', 'https-redirection');?></p>
237 <p><a href="options-permalink.php"><?php _e('Enable Permalinks', 'https-redirection');?></a></p>
238 </div>
239 <?php }?>
240 </div>
241 </div>
242 <div class="postbox">
243 <h3 class="hndle"><label for="title"><?php _e("Debug Logging", 'https-redirection');?></label></h3>
244 <div class="inside">
245 <p>
246 <?php _e('Debug logging can be useful to troubleshoot issues on your site. keep it disabled unless you are troubleshooting.', 'https-redirection');?>
247 </p>
248 <form id="ehssl_debug_settings_form" method="post" action="">
249 <table class="form-table">
250 <tr valign="top">
251 <th scope="row">
252 <label for="ehssl-debug-enable-checkbox">
253 <?php _e('Enable Debug Logging', 'https-redirection');?>
254 </label>
255 </th>
256 <td>
257 <input type="checkbox" id="ehssl-debug-enable-checkbox" name="enable_debug_logging" value="1" <?php if ('1' == $is_debug_logging_enabled) {echo "checked=\"checked\" ";}?> />
258 <br />
259 <p class="description"><?php _e("Check this option to enable debug logging.", 'https-redirection');?></p>
260 <p class="description">
261 <a href="<?php echo wp_nonce_url(get_admin_url() . '?ehssl-debug-action=view_log', 'ehssl_view_log_nonce'); ?>" target="_blank">
262 <?php _e('Click here', 'https-redirection')?>
263 </a>
264 <?php _e(' to view log file.', 'https-redirection');?>
265 <br>
266 <a id="ehssl-reset-log" href="#0" style="color: red">
267 <?php _e('Click here', 'https-redirection');?>
268 </a>
269 <?php _e(' to reset log file.', 'https-redirection');?>
270 </p>
271 </td>
272 </tr>
273 </table>
274
275 <input type="submit" name="ehssl_debug_log_form_submit" class="button-primary" value="<?php _e('Save Changes')?>" />
276 <?php wp_nonce_field('ehssl_debug_settings_nonce');?>
277 </form>
278 </div><!-- end of inside -->
279 </div><!-- end of postbox -->
280 <script>
281 jQuery( document ).ready( function( $ ) {
282 const ehssl_ajaxurl = "<?php echo get_admin_url() . 'admin-ajax.php' ?>";
283 const ehssl_ajax_nonce = "<?php echo wp_create_nonce('ehssl_settings_ajax_nonce') ?>";
284 $( '#ehssl-reset-log' ).on('click', function( e ) {
285 e.preventDefault();
286 $.post( ehssl_ajaxurl,
287 {
288 action: 'ehssl_reset_log',
289 nonce: ehssl_ajax_nonce
290 },
291 function( result ) {
292 if ( result === '1' ) {
293 alert( '<?php _e('Log file has been reset.', 'https-redirection') ?>' );
294 } else {
295 alert( '<?php _e('Error trying to reset log: ' , 'https-redirection') ?>' + result );
296 }
297 } );
298 } );
299 } );
300 </script>
301 <?php
302 }
303
304 public function render_mixed_content_tab()
305 {
306 global $httpsrdrctn_options;
307
308 $is_https_redirection_enabled = isset($httpsrdrctn_options['https']) && esc_attr($httpsrdrctn_options['https']) == '1' ? true : false;
309
310 if (isset($_POST['ehssl_mixed_content_form_submit']) && check_admin_referer('ehssl_mixed_content_settings_nonce')) {
311 $httpsrdrctn_options['force_resources'] = isset($_POST['httpsrdrctn_force_resources']) ? esc_attr($_POST['httpsrdrctn_force_resources']) : 0;
312 update_option('httpsrdrctn_options', $httpsrdrctn_options)
313
314 ?>
315 <div class="notice notice-success">
316 <p><?php _e("Settings Saved.", 'https-redirection');?></p>
317 </div>
318 <?php
319 }
320 ?>
321 <div class="postbox">
322 <h3 class="hndle"><label for="title"><?php _e("Static Resources", 'https-redirection');?></label></h3>
323 <div class="inside">
324 <?php if(!$is_https_redirection_enabled){ ?>
325 <div class="ehssl-yellow-box">
326 <p>
327 <?php _e("HTTPS redirection is turned off. Turn it on first to change these settings below!", 'https-redirection');?>
328 </p>
329 </div>
330 <?php } ?>
331 <form action="" method="POST">
332 <table class="form-table">
333 <tr valign="top">
334 <th scope="row"><?php _e('Force Resources to Use HTTPS URL', 'https-redirection');?></th>
335 <td>
336 <label>
337 <input type="checkbox" <?php echo !$is_https_redirection_enabled ? "disabled" : ''; ?> name="httpsrdrctn_force_resources" value="1" <?php echo (isset($httpsrdrctn_options['force_resources']) && $httpsrdrctn_options['force_resources'] == '1') ? 'checked="checked"' : ''; ?> />
338 </label>
339 <br />
340 <p class="description"><?php _e('When checked, the plugin will force load HTTPS URL for any static resources in your content. Example: if you have have an image embedded in a post with a NON-HTTPS URL, this option will change that to a HTTPS URL.', 'https-redirection');?></p>
341 </td>
342 </tr>
343 </table>
344 <input type="submit" name="ehssl_mixed_content_form_submit" class="button-primary" value="<?php _e('Save Changes')?>" <?php if (!$is_https_redirection_enabled) {echo "disabled";}?>/>
345 <?php wp_nonce_field('ehssl_mixed_content_settings_nonce');?>
346 </form>
347 </div><!-- end of inside -->
348 </div><!-- end of postbox -->
349 <?php
350 }
351 } // End class