HC Custom WP-Admin URL - Version 1.3.1

Version Description

  • Fixed bug on some WordPress instances where there was a problem with getting the site home path
Download this release

Release Info

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

Code changes from version 1.3 to 1.3.1

Files changed (2) hide show
  1. hc-custom-wp-admin-url.php +22 -14
  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.3
5
  Plugin URI: http://wordpress.org/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
@@ -120,11 +120,11 @@ if (!class_exists('HC_CustomWPAdminURL')) {
120
  // return parsed url
121
  function get_url() {
122
  $url = array();
123
- $url['scheme'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off") ? "https" : "http");
124
  $url['domain'] = $_SERVER['HTTP_HOST'];
125
- $url['port'] = (isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"]) ? $_SERVER["SERVER_PORT"] : "";
126
  $url['rewrite_base'] = ($host = explode( (($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'], get_bloginfo('url') ) ) ? preg_replace("/^\//", "", implode("", $host)) : "";
127
- $url['path'] = ($url['rewrite_base']) ? implode("", explode("/" . $url['rewrite_base'], $_SERVER["SCRIPT_NAME"])) : $_SERVER["SCRIPT_NAME"];
128
  $url['query'] = $_SERVER['QUERY_STRING'];
129
  return $url;
130
  }
@@ -133,16 +133,8 @@ if (!class_exists('HC_CustomWPAdminURL')) {
133
  // just chek if we are on the right place
134
  if (in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php')) && (get_option('custom_wpadmin_slug') != false && get_option('custom_wpadmin_slug') != '')) {
135
 
136
- // inlcude file.php
137
- $DS = DIRECTORY_SEPARATOR;
138
- if (file_exists(dirname(__FILE__) . $DS . '..' . $DS . '..' . $DS . '..' . $DS . 'wp-admin' . $DS . 'includes' . $DS . 'file.php')) {
139
- include(dirname(__FILE__) . $DS . '..' . $DS . '..' . $DS . '..' . $DS . 'wp-admin' . $DS . 'includes' . $DS . 'file.php');
140
- } else {
141
- return; // if hierarchy is messed up, don't go further
142
- }
143
-
144
  // check if our plugin have written necesery line to .htaccess, sometimes WP doesn't write correctly so we don't want to disable login in that case
145
- $markerdata = explode("\n", implode('', file(get_home_path() . '.htaccess')));
146
  $found = false;
147
  $url = $this->get_url();
148
  foreach ($markerdata as $line) {
@@ -155,6 +147,21 @@ if (!class_exists('HC_CustomWPAdminURL')) {
155
  }
156
  }
157
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  }
159
 
160
  $hc_custom_wpadmin_url = new HC_CustomWPAdminURL();
@@ -164,4 +171,5 @@ if (!class_exists('HC_CustomWPAdminURL')) {
164
  add_action('admin_init', array($hc_custom_wpadmin_url, 'custom_admin_url'));
165
  add_action('login_init', array($hc_custom_wpadmin_url, 'check_login'));
166
 
167
- }
 
1
  <?php
2
  /*
3
  Plugin Name: HC Custom WP-Admin URL
4
+ Version: 1.3.1
5
  Plugin URI: http://wordpress.org/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
120
  // return parsed url
121
  function get_url() {
122
  $url = array();
123
+ $url['scheme'] = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off" ? "https" : "http";
124
  $url['domain'] = $_SERVER['HTTP_HOST'];
125
+ $url['port'] = isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"] ? $_SERVER["SERVER_PORT"] : "";
126
  $url['rewrite_base'] = ($host = explode( (($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'], get_bloginfo('url') ) ) ? preg_replace("/^\//", "", implode("", $host)) : "";
127
+ $url['path'] = $url['rewrite_base'] ? implode("", explode("/" . $url['rewrite_base'], $_SERVER["SCRIPT_NAME"])) : $_SERVER["SCRIPT_NAME"];
128
  $url['query'] = $_SERVER['QUERY_STRING'];
129
  return $url;
130
  }
133
  // just chek if we are on the right place
134
  if (in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php')) && (get_option('custom_wpadmin_slug') != false && get_option('custom_wpadmin_slug') != '')) {
135
 
 
 
 
 
 
 
 
 
136
  // check if our plugin have written necesery line to .htaccess, sometimes WP doesn't write correctly so we don't want to disable login in that case
137
+ $markerdata = explode("\n", implode('', file($this->get_home_path() . '.htaccess')));
138
  $found = false;
139
  $url = $this->get_url();
140
  foreach ($markerdata as $line) {
147
  }
148
  }
149
  }
150
+
151
+ /* Taken from "/wp-admin/includes/file.php" */
152
+ function get_home_path() {
153
+ $home = get_option( 'home' );
154
+ $siteurl = get_option( 'siteurl' );
155
+ if ( ! empty( $home ) && 0 !== strcasecmp( $home, $siteurl ) ) {
156
+ $wp_path_rel_to_home = str_ireplace( $home, '', $siteurl ); /* $siteurl - $home */
157
+ $pos = strripos( str_replace( '\\', '/', $_SERVER['SCRIPT_FILENAME'] ), trailingslashit( $wp_path_rel_to_home ) );
158
+ $home_path = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos );
159
+ $home_path = trailingslashit( $home_path );
160
+ } else {
161
+ $home_path = ABSPATH;
162
+ }
163
+ return $home_path;
164
+ }
165
  }
166
 
167
  $hc_custom_wpadmin_url = new HC_CustomWPAdminURL();
171
  add_action('admin_init', array($hc_custom_wpadmin_url, 'custom_admin_url'));
172
  add_action('login_init', array($hc_custom_wpadmin_url, 'check_login'));
173
 
174
+ }
175
+
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
5
  Tested up to: 3.5.1
6
- Stable tag: 1.3
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 plugins which modify .htaccess file.
45
 
46
  == Changelog ==
47
 
 
 
 
48
  = 1.3 =
49
  * Fixed redirection bug of password protected pages
50
 
3
  Tags: plugin, administration, admin, custom url, login, security, wp-admin, wp-login
4
  Requires at least: 3.2
5
  Tested up to: 3.5.1
6
+ Stable tag: 1.3.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
45
 
46
  == Changelog ==
47
 
48
+ = 1.3.1 =
49
+ * Fixed bug on some WordPress instances where there was a problem with getting the site home path
50
+
51
  = 1.3 =
52
  * Fixed redirection bug of password protected pages
53