HC Custom WP-Admin URL - Version 1.1

Version Description

  • Fixed URL for "default" permalink settings
  • Fixed URL with trailing slash at the end
Download this release

Release Info

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

Code changes from version 1.0 to 1.1

Files changed (2) hide show
  1. hc-custom-wp-admin-url.php +58 -16
  2. readme.txt +19 -8
hc-custom-wp-admin-url.php CHANGED
@@ -1,8 +1,8 @@
1
  <?php
2
  /*
3
  Plugin Name: HC Custom WP-Admin URL
4
- Version: 1.0
5
- Plugin URI:
6
  Description: Small and simple plugin that allows you to change url of wp-admin
7
  Author: Some Web Media
8
  Author URI: http://someweblog.com/
@@ -17,27 +17,69 @@ if (!class_exists('hc_custom_wpadmin_url')) {
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
- // write to db
24
- update_option('custom_wpadmin_slug', sanitize_key(wp_strip_all_tags($_POST['custom_wpadmin_slug'])));
25
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  // write rewrite rules right away
27
- if (get_option('custom_wpadmin_slug') != '') {
28
- add_rewrite_rule($_POST['custom_wpadmin_slug'].'/?$', 'wp-login.php', 'top');
29
  } else {
30
  flush_rewrite_rules();
31
  }
32
  }
33
- add_settings_field('custom_wpadmin_slug', 'WP-Admin page slug', array($this, 'options_page'), 'permalink', 'optional', array('label_for' => 'custom_wpadmin_slug'));
34
  register_setting('permalink', 'custom_wpadmin_slug', 'strval');
35
  }
36
 
37
  function options_page() {
38
  ?>
39
  <input id="custom_wpadmin_slug" name="custom_wpadmin_slug" type="text" class="regular-text code" value="<?php echo get_option('custom_wpadmin_slug'); ?>" />
40
- <p class="howto"><?php 'Allowed characters are a-z, 0-9, - and _'; ?></p>
41
  <?php
42
  }
43
 
@@ -50,14 +92,14 @@ if (!class_exists('hc_custom_wpadmin_url')) {
50
  list($file, $arguments) = explode("?", $_SERVER['REQUEST_URI']);
51
  // if on localhost remove subdir
52
  $file = ($url['rewrite_base']) ? implode("", explode("/" . $url['rewrite_base'], $file)) : $file;
53
-
54
  if("/wp-login.php?loggedout=true" == $file . "?" . $arguments) {
55
  session_destroy();
56
  header("location: " . $url['scheme'] . "://" . $url['domain'] . "/" . $url['rewrite_base'] . "/");
57
  exit();
58
  } else if ("action=logout" == substr($arguments, 0, 13)) {
59
  unset($_SESSION['valid_login']);
60
- } else if ($file == "/" . get_option('custom_wpadmin_slug')) {
61
  $_SESSION['valid_login'] = true;
62
  } else if (isset($_SESSION['valid_login'])) {
63
  // do nothing
@@ -81,13 +123,13 @@ if (!class_exists('hc_custom_wpadmin_url')) {
81
  }
82
 
83
  $hc_custom_wpadmin_url = new hc_custom_wpadmin_url();
84
-
85
- // rewrite urls
86
  add_filter('generate_rewrite_rules', array($hc_custom_wpadmin_url, 'rewrite_admin_url'));
87
  add_action('admin_init', array($hc_custom_wpadmin_url, 'custom_admin_url'));
88
-
 
89
  if (in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php')) && get_option('custom_wpadmin_slug') != '') {
90
  $hc_custom_wpadmin_url->custom_login();
91
  }
92
-
93
  }
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
8
  Author URI: http://someweblog.com/
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']))
36
+ $home_root = trailingslashit($home_root['path']);
37
+ else
38
+ $home_root = '/';
39
+ // create rules
40
+ $rules = "<IfModule mod_rewrite.c>\n";
41
+ $rules .= "RewriteEngine On\n";
42
+ $rules .= "RewriteRule ^$wpadmin_slug/?$ ".$home_root."wp-login.php [QSA,L]\n";
43
+ $rules .= "</IfModule>";
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 = '';
52
+ foreach ($markerdata as $line) {
53
+ if ($line == '# BEGIN WPAdminURL')
54
+ $found = true;
55
+ if (!$found)
56
+ $newdata .= "$line\n";
57
+ if ($line == '# END WPAdminURL')
58
+ $found = false;
59
+ }
60
+ // write back
61
+ $f = @fopen($home_path . '.htaccess', 'w');
62
+ fwrite($f, $newdata);
63
+ }
64
+
65
+ // save to db
66
+ update_option('custom_wpadmin_slug', $wpadmin_slug);
67
+
68
  // write rewrite rules right away
69
+ if ($wpadmin_slug != '') {
70
+ add_rewrite_rule($wpadmin_slug.'/?$', 'wp-login.php', 'top');
71
  } else {
72
  flush_rewrite_rules();
73
  }
74
  }
75
+ add_settings_field('custom_wpadmin_slug', 'WP-Admin slug', array($this, 'options_page'), 'permalink', 'optional', array('label_for' => 'custom_wpadmin_slug'));
76
  register_setting('permalink', 'custom_wpadmin_slug', 'strval');
77
  }
78
 
79
  function options_page() {
80
  ?>
81
  <input id="custom_wpadmin_slug" name="custom_wpadmin_slug" type="text" class="regular-text code" value="<?php echo get_option('custom_wpadmin_slug'); ?>" />
82
+ <p class="howto">Allowed characters are a-z, 0-9, - and _</p>
83
  <?php
84
  }
85
 
92
  list($file, $arguments) = explode("?", $_SERVER['REQUEST_URI']);
93
  // if on localhost remove subdir
94
  $file = ($url['rewrite_base']) ? implode("", explode("/" . $url['rewrite_base'], $file)) : $file;
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
123
  }
124
 
125
  $hc_custom_wpadmin_url = new hc_custom_wpadmin_url();
126
+
127
+ // add hooks
128
  add_filter('generate_rewrite_rules', array($hc_custom_wpadmin_url, 'rewrite_admin_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
  }
readme.txt CHANGED
@@ -3,34 +3,41 @@ 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.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
- Small and simple plugin that allows you to change url of wp-admin
11
 
12
  == Description ==
13
 
14
- With this plugin you can change wp-admin and wp-login.php to any of your choice.
15
- Instead of `http://example.org/wp-admin/` and `http://example.org/wp-login.php` you can have `http://example.org/admin` or `http://example.org/banana`
16
 
17
- New field will be added to Settings->Permalinks section called **WP-Admin page slug**. All you have to do is to write your desired WP Admin slug and save settings.
 
 
 
 
18
 
19
  == Installation ==
20
 
21
  1. Upload `hc-custom-wp-admin-url.php` to the `/wp-content/plugins/` directory
22
  2. Activate the plugin through the 'Plugins' menu in WordPress
23
  3. Go to Permalink Options page inside the administration area
24
- 4. Set the field **WP-Admin page slug** to the desired one
25
 
26
  == Frequently Asked Questions ==
27
 
28
  = Does this work with Multisite =
29
  Not yet. Soon!
30
 
31
- = What about the default URLs? =
 
 
32
 
33
- Old WP Admin urls `http://example.org/wp-admin/` and `http://example.org/wp-login.php` will not be usable until you clear the **WP-Admin page slug** field from Permalink Options page or uninstal the plugin
 
 
34
 
35
  == Screenshots ==
36
 
@@ -38,6 +45,10 @@ Old WP Admin urls `http://example.org/wp-admin/` and `http://example.org/wp-logi
38
 
39
  == Changelog ==
40
 
 
 
 
 
41
  = 1.0 =
42
  * Initial release
43
  * Sets basic login and admin redirects and checks
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
 
10
+ Small and simple security plugin that allows you to change url of wp-admin
11
 
12
  == Description ==
13
 
14
+ Want to reduce the possibility of your website been hacked or hijacked?
 
15
 
16
+ With this plugin you can change wp-admin and wp-login.php to any of your choice, making it impossible for the hackers to access your administration login page.
17
+ Instead of `http://yourdomain.com/wp-admin/` and `http://yourdomain.com/wp-login.php` you can have `http://yourdomain.com/admin` or `http://yourdomain.com/banana`
18
+
19
+ Its simple to use.
20
+ New field will be added to **Settings** -> **Permalinks** section called **WP-Admin slug**. All you have to do is to write your desired WP Admin slug and save the settings.
21
 
22
  == Installation ==
23
 
24
  1. Upload `hc-custom-wp-admin-url.php` to the `/wp-content/plugins/` directory
25
  2. Activate the plugin through the 'Plugins' menu in WordPress
26
  3. Go to Permalink Options page inside the administration area
27
+ 4. Set the field **WP-Admin slug** to the desired one
28
 
29
  == Frequently Asked Questions ==
30
 
31
  = Does this work with Multisite =
32
  Not yet. Soon!
33
 
34
+ = What about the default Admin URLs? =
35
+
36
+ Old WP Admin urls `http://yourdomain.com/wp-admin/` and `http://yourdomain.com/wp-login.php` will not be usable until you clear the **WP-Admin slug** field from Permalink Options page or uninstal the plugin
37
 
38
+ = Anything important I should know? =
39
+
40
+ Be careful if using this plugin with other which modify .htaccess file. Also if you are having trouble with your .htaccess file not being generated properly, try deleting it and re-saving Permalink options.
41
 
42
  == Screenshots ==
43
 
45
 
46
  == Changelog ==
47
 
48
+ = 1.1 =
49
+ * Fixed URL for "default" permalink settings
50
+ * Fixed URL with trailing slash at the end
51
+
52
  = 1.0 =
53
  * Initial release
54
  * Sets basic login and admin redirects and checks