HC Custom WP-Admin URL - Version 1.1.2

Version Description

  • Fixed redirection bug when slug set to empty
Download this release

Release Info

Developer SomeWebMedia
Plugin Icon 128x128 HC Custom WP-Admin URL
Version 1.1.2
Comparing to
See all releases

Code changes from version 1.1 to 1.1.2

Files changed (2) hide show
  1. hc-custom-wp-admin-url.php +15 -12
  2. readme.txt +4 -1
hc-custom-wp-admin-url.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  Plugin Name: HC Custom WP-Admin URL
4
- Version: 1.1
5
  Plugin URI: http://wordpress.org/extend/plugins/hc-custom-wp-admin-url/
6
  Description: Small and simple plugin that allows you to change url of wp-admin
7
  Author: Some Web Media
@@ -15,21 +15,22 @@ if (!class_exists('hc_custom_wpadmin_url')) {
15
  function rewrite_admin_url($wp_rewrite) {
16
  // be sure rules are written every time permalinks are updated
17
  $rule = get_option('custom_wpadmin_slug');
18
- add_rewrite_rule($rule.'/?$', 'wp-login.php', 'top');
 
19
  }
20
 
21
  function custom_admin_url() {
22
  if (isset($_POST['custom_wpadmin_slug'])) {
23
 
24
  // sanitize input
25
- $wpadmin_slug = sanitize_key(wp_strip_all_tags($_POST['custom_wpadmin_slug']));
26
  $home_path = get_home_path();
27
 
28
  // check if permalinks are turned off, if so force push rules to .htaccess
29
- if (isset($_POST['selection']) && $_POST['selection'] == '') {
30
  // check if .htaccess is writable
31
  if ((!file_exists($home_path . '.htaccess') && is_writable($home_path)) || is_writable($home_path . '.htaccess')) {
32
-
33
  // taken from wp-includes/rewrite.php
34
  $home_root = parse_url(home_url());
35
  if (isset($home_root['path']))
@@ -44,8 +45,8 @@ if (!class_exists('hc_custom_wpadmin_url')) {
44
  // write to .htaccess
45
  insert_with_markers($home_path . '.htaccess', 'WPAdminURL', explode("\n", $rules));
46
  }
47
- } else if (isset($_POST['selection'])) {
48
- // remove rules if permalinks "default" option was enabled
49
  $markerdata = explode("\n", implode('', file($home_path . '.htaccess')));
50
  $found = false;
51
  $newdata = '';
@@ -95,16 +96,18 @@ if (!class_exists('hc_custom_wpadmin_url')) {
95
 
96
  if("/wp-login.php?loggedout=true" == $file . "?" . $arguments) {
97
  session_destroy();
98
- header("location: " . $url['scheme'] . "://" . $url['domain'] . "/" . $url['rewrite_base'] . "/");
99
  exit();
100
  } else if ("action=logout" == substr($arguments, 0, 13)) {
101
  unset($_SESSION['valid_login']);
 
 
102
  } else if ($file == "/" . get_option('custom_wpadmin_slug') || $file == "/" . get_option('custom_wpadmin_slug') . "/") {
103
  $_SESSION['valid_login'] = true;
104
- } else if (isset($_SESSION['valid_login'])) {
105
- // do nothing
106
  } else {
107
- header("location: " . $url['scheme'] . "://" . $url['domain'] . "/" . $url['rewrite_base'] . "/");
108
  exit();
109
  }
110
  }
@@ -129,7 +132,7 @@ if (!class_exists('hc_custom_wpadmin_url')) {
129
  add_action('admin_init', array($hc_custom_wpadmin_url, 'custom_admin_url'));
130
 
131
  // check login page slug
132
- if (in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php')) && get_option('custom_wpadmin_slug') != '') {
133
  $hc_custom_wpadmin_url->custom_login();
134
  }
135
  }
1
  <?php
2
  /*
3
  Plugin Name: HC Custom WP-Admin URL
4
+ Version: 1.1.2
5
  Plugin URI: http://wordpress.org/extend/plugins/hc-custom-wp-admin-url/
6
  Description: Small and simple plugin that allows you to change url of wp-admin
7
  Author: Some Web Media
15
  function rewrite_admin_url($wp_rewrite) {
16
  // be sure rules are written every time permalinks are updated
17
  $rule = get_option('custom_wpadmin_slug');
18
+ if ($rule != '')
19
+ add_rewrite_rule($rule.'/?$', 'wp-login.php', 'top');
20
  }
21
 
22
  function custom_admin_url() {
23
  if (isset($_POST['custom_wpadmin_slug'])) {
24
 
25
  // sanitize input
26
+ $wpadmin_slug = trim(sanitize_key(wp_strip_all_tags($_POST['custom_wpadmin_slug'])));
27
  $home_path = get_home_path();
28
 
29
  // check if permalinks are turned off, if so force push rules to .htaccess
30
+ if (isset($_POST['selection']) && $_POST['selection'] == '' && $wpadmin_slug != '') {
31
  // check if .htaccess is writable
32
  if ((!file_exists($home_path . '.htaccess') && is_writable($home_path)) || is_writable($home_path . '.htaccess')) {
33
+
34
  // taken from wp-includes/rewrite.php
35
  $home_root = parse_url(home_url());
36
  if (isset($home_root['path']))
45
  // write to .htaccess
46
  insert_with_markers($home_path . '.htaccess', 'WPAdminURL', explode("\n", $rules));
47
  }
48
+ } else if (isset($_POST['selection']) || (isset($_POST['selection']) && $_POST['selection'] == '' && $wpadmin_slug == '')) {
49
+ // remove rules if permalinks were enabled
50
  $markerdata = explode("\n", implode('', file($home_path . '.htaccess')));
51
  $found = false;
52
  $newdata = '';
96
 
97
  if("/wp-login.php?loggedout=true" == $file . "?" . $arguments) {
98
  session_destroy();
99
+ header("location: " . $url['scheme'] . "://" . $url['domain'] . "/" . $url['rewrite_base']);
100
  exit();
101
  } else if ("action=logout" == substr($arguments, 0, 13)) {
102
  unset($_SESSION['valid_login']);
103
+ } else if ("action=lostpassword" == $url['query']) {
104
+ // let user to this page
105
  } else if ($file == "/" . get_option('custom_wpadmin_slug') || $file == "/" . get_option('custom_wpadmin_slug') . "/") {
106
  $_SESSION['valid_login'] = true;
107
+ } else if (isset($_SESSION['valid_login'])) {
108
+ // let them pass
109
  } else {
110
+ header("location: " . $url['scheme'] . "://" . $url['domain'] . "/" . $url['rewrite_base']);
111
  exit();
112
  }
113
  }
132
  add_action('admin_init', array($hc_custom_wpadmin_url, 'custom_admin_url'));
133
 
134
  // check login page slug
135
+ if (in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php')) && (get_option('custom_wpadmin_slug') != false && get_option('custom_wpadmin_slug') != '')) {
136
  $hc_custom_wpadmin_url->custom_login();
137
  }
138
  }
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: SomeWebMedia
3
  Tags: plugin, administration, admin, custom url, login, security, wp-admin, wp-login
4
  Requires at least: 3.2.0
5
  Tested up to: 3.5.1
6
- Stable tag: 1.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -45,6 +45,9 @@ Be careful if using this plugin with other which modify .htaccess file. Also if
45
 
46
  == Changelog ==
47
 
 
 
 
48
  = 1.1 =
49
  * Fixed URL for "default" permalink settings
50
  * Fixed URL with trailing slash at the end
3
  Tags: plugin, administration, admin, custom url, login, security, wp-admin, wp-login
4
  Requires at least: 3.2.0
5
  Tested up to: 3.5.1
6
+ Stable tag: 1.1.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
45
 
46
  == Changelog ==
47
 
48
+ = 1.1.2 =
49
+ * Fixed redirection bug when slug set to empty
50
+
51
  = 1.1 =
52
  * Fixed URL for "default" permalink settings
53
  * Fixed URL with trailing slash at the end