Version Description
- Initial release
- Sets basic login and admin redirects and checks
- Able to change link through permalink options page
Download this release
Release Info
Developer | SomeWebMedia |
Plugin | HC Custom WP-Admin URL |
Version | 1.0 |
Comparing to | |
See all releases |
Version 1.0
- hc-custom-wp-admin-url.php +93 -0
- readme.txt +44 -0
hc-custom-wp-admin-url.php
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/
|
9 |
+
*/
|
10 |
+
|
11 |
+
if (!class_exists('hc_custom_wpadmin_url')) {
|
12 |
+
|
13 |
+
class hc_custom_wpadmin_url {
|
14 |
+
|
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 |
+
// 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 |
+
|
44 |
+
// custom login url
|
45 |
+
function custom_login() {
|
46 |
+
// start session if doesn't exist
|
47 |
+
if (!session_id()) session_start();
|
48 |
+
$url = $this->get_url();
|
49 |
+
// see referal url by the web client
|
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
|
64 |
+
} else {
|
65 |
+
header("location: " . $url['scheme'] . "://" . $url['domain'] . "/" . $url['rewrite_base'] . "/");
|
66 |
+
exit();
|
67 |
+
}
|
68 |
+
}
|
69 |
+
|
70 |
+
// return parsed url
|
71 |
+
function get_url() {
|
72 |
+
$url = array();
|
73 |
+
$url['scheme'] = (($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http");
|
74 |
+
$url['domain'] = $_SERVER['HTTP_HOST'];
|
75 |
+
$url['port'] = ($_SERVER["SERVER_PORT"]) ? $_SERVER["SERVER_PORT"] : "";
|
76 |
+
$url['rewrite_base'] = ($host = explode( (($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'], get_bloginfo('url') ) ) ? preg_replace("/^\//", "", implode("", $host)) : "";
|
77 |
+
$url['path'] = ($url['rewrite_base']) ? implode("", explode("/" . $url['rewrite_base'], $_SERVER["SCRIPT_NAME"])) : $_SERVER["SCRIPT_NAME"];
|
78 |
+
$url['query'] = $_SERVER['QUERY_STRING'];
|
79 |
+
return $url;
|
80 |
+
}
|
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 |
+
}
|
readme.txt
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== HC Custom WP-Admin URL ===
|
2 |
+
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 |
+
|
37 |
+
1. Blog Permalinks Options page, where you are able to set your custom URL
|
38 |
+
|
39 |
+
== Changelog ==
|
40 |
+
|
41 |
+
= 1.0 =
|
42 |
+
* Initial release
|
43 |
+
* Sets basic login and admin redirects and checks
|
44 |
+
* Able to change link through permalink options page
|