Version Description
Download this release
Release Info
Developer | iseulde |
Plugin | Rename wp-login.php |
Version | 2.5.3 |
Comparing to | |
See all releases |
Code changes from version 2.5.1 to 2.5.3
- index.php +0 -0
- readme.txt +8 -9
- rename-wp-login.php +95 -261
index.php
DELETED
File without changes
|
readme.txt
CHANGED
@@ -1,12 +1,11 @@
|
|
1 |
-
=== Rename wp-login.php (
|
2 |
-
|
3 |
-
Contributors:
|
4 |
-
Tags:
|
5 |
-
Requires at least: 4.
|
6 |
-
Tested up to:
|
7 |
-
Stable tag:
|
8 |
-
License:
|
9 |
-
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
11 |
Change wp-login.php to anything you want.
|
12 |
|
1 |
+
=== Rename wp-login.php (unsupported) ===
|
2 |
+
|
3 |
+
Contributors: iseulde
|
4 |
+
Tags: rename, login, wp-login, wp-login.php, custom login url
|
5 |
+
Requires at least: 4.4
|
6 |
+
Tested up to: 4.4
|
7 |
+
Stable tag: 2.5.3
|
8 |
+
License: GPL-2.0+
|
|
|
9 |
|
10 |
Change wp-login.php to anything you want.
|
11 |
|
rename-wp-login.php
CHANGED
@@ -1,117 +1,88 @@
|
|
1 |
<?php
|
2 |
|
3 |
/*
|
4 |
-
Plugin Name: Rename wp-login.php (
|
5 |
-
Plugin URI:
|
6 |
-
Description: Change wp-login.php to whatever you want.
|
7 |
-
|
8 |
-
Author
|
9 |
-
|
10 |
-
Text Domain:
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
class Rename_WP_Login {
|
19 |
-
|
20 |
private $wp_login_php;
|
21 |
|
22 |
private function basename() {
|
23 |
-
|
24 |
return plugin_basename( __FILE__ );
|
25 |
-
|
26 |
}
|
27 |
|
28 |
private function path() {
|
29 |
-
|
30 |
return trailingslashit( dirname( __FILE__ ) );
|
31 |
-
|
32 |
}
|
33 |
|
34 |
private function use_trailing_slashes() {
|
35 |
-
|
36 |
-
return ( '/' === substr( get_option( 'permalink_structure' ), -1, 1 ) );
|
37 |
-
|
38 |
}
|
39 |
|
40 |
private function user_trailingslashit( $string ) {
|
41 |
-
|
42 |
-
return $this->use_trailing_slashes()
|
43 |
-
? trailingslashit( $string )
|
44 |
-
: untrailingslashit( $string );
|
45 |
-
|
46 |
}
|
47 |
|
48 |
private function wp_template_loader() {
|
49 |
-
|
50 |
global $pagenow;
|
51 |
|
52 |
$pagenow = 'index.php';
|
53 |
|
54 |
if ( ! defined( 'WP_USE_THEMES' ) ) {
|
55 |
-
|
56 |
define( 'WP_USE_THEMES', true );
|
57 |
-
|
58 |
}
|
59 |
|
60 |
wp();
|
61 |
|
62 |
if ( $_SERVER['REQUEST_URI'] === $this->user_trailingslashit( str_repeat( '-/', 10 ) ) ) {
|
63 |
-
|
64 |
$_SERVER['REQUEST_URI'] = $this->user_trailingslashit( '/wp-login-php/' );
|
65 |
-
|
66 |
}
|
67 |
|
68 |
require_once( ABSPATH . WPINC . '/template-loader.php' );
|
69 |
|
70 |
die;
|
71 |
-
|
72 |
}
|
73 |
|
74 |
private function new_login_slug() {
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
82 |
return $slug;
|
83 |
-
|
84 |
}
|
85 |
-
|
86 |
}
|
87 |
|
88 |
public function new_login_url( $scheme = null ) {
|
89 |
-
|
90 |
if ( get_option( 'permalink_structure' ) ) {
|
91 |
-
|
92 |
return $this->user_trailingslashit( home_url( '/', $scheme ) . $this->new_login_slug() );
|
93 |
-
|
94 |
-
}
|
95 |
-
|
96 |
-
else {
|
97 |
-
|
98 |
return home_url( '/', $scheme ) . '?' . $this->new_login_slug();
|
99 |
-
|
100 |
}
|
101 |
-
|
102 |
}
|
103 |
|
104 |
public function __construct() {
|
105 |
-
|
106 |
global $wp_version;
|
107 |
|
108 |
if ( version_compare( $wp_version, '4.0-RC1-src', '<' ) ) {
|
109 |
-
|
110 |
add_action( 'admin_notices', array( $this, 'admin_notices_incompatible' ) );
|
111 |
add_action( 'network_admin_notices', array( $this, 'admin_notices_incompatible' ) );
|
112 |
|
113 |
return;
|
114 |
-
|
115 |
}
|
116 |
|
117 |
register_activation_hook( $this->basename(), array( $this, 'activate' ) );
|
@@ -121,23 +92,17 @@ if ( defined( 'ABSPATH' )
|
|
121 |
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
|
122 |
add_action( 'network_admin_notices', array( $this, 'admin_notices' ) );
|
123 |
|
124 |
-
if ( is_multisite()
|
125 |
-
&& ! function_exists( 'is_plugin_active_for_network' ) ) {
|
126 |
-
|
127 |
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
128 |
-
|
129 |
}
|
130 |
|
131 |
add_filter( 'plugin_action_links_' . $this->basename(), array( $this, 'plugin_action_links' ) );
|
132 |
|
133 |
-
if ( is_multisite()
|
134 |
-
&& is_plugin_active_for_network( $this->basename() ) ) {
|
135 |
-
|
136 |
add_filter( 'network_admin_plugin_action_links_' . $this->basename(), array( $this, 'plugin_action_links' ) );
|
137 |
|
138 |
add_action( 'wpmu_options', array( $this, 'wpmu_options' ) );
|
139 |
add_action( 'update_wpmu_options', array( $this, 'update_wpmu_options' ) );
|
140 |
-
|
141 |
}
|
142 |
|
143 |
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 1 );
|
@@ -150,64 +115,43 @@ if ( defined( 'ABSPATH' )
|
|
150 |
add_filter( 'site_option_welcome_email', array( $this, 'welcome_email' ) );
|
151 |
|
152 |
remove_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 );
|
153 |
-
|
154 |
}
|
155 |
|
156 |
public function admin_notices_incompatible() {
|
157 |
-
|
158 |
echo '<div class="error"><p>Please upgrade to the latest version of WordPress to activate <strong>Rename wp-login.php</strong>.</p></div>';
|
159 |
-
|
160 |
}
|
161 |
|
162 |
public function activate() {
|
163 |
-
|
164 |
add_option( 'rwl_redirect', '1' );
|
165 |
-
|
166 |
delete_option( 'rwl_admin' );
|
167 |
-
|
168 |
}
|
169 |
|
170 |
public static function uninstall() {
|
171 |
-
|
172 |
global $wpdb;
|
173 |
|
174 |
if ( is_multisite() ) {
|
175 |
-
|
176 |
$blogs = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" );
|
177 |
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
switch_to_blog( $blog );
|
183 |
-
|
184 |
-
delete_option( 'rwl_page' );
|
185 |
-
|
186 |
-
}
|
187 |
-
|
188 |
-
restore_current_blog();
|
189 |
-
|
190 |
}
|
191 |
|
192 |
-
|
193 |
-
|
194 |
-
}
|
195 |
-
|
196 |
-
else {
|
197 |
|
|
|
|
|
198 |
delete_option( 'rwl_page' );
|
199 |
-
|
200 |
}
|
201 |
-
|
202 |
}
|
203 |
|
204 |
public function wpmu_options() {
|
205 |
-
|
206 |
$out = '';
|
207 |
|
208 |
$out .= '<h3>Rename wp-login.php</h3>';
|
209 |
$out .= '<p>This option allows you to set a networkwide default, which can be overridden by individual sites. Simply go to to the site’s permalink settings to change the url.</p>';
|
210 |
-
$out .= '<p>Need help? Try the <a href="http://wordpress.org/support/plugin/rename-wp-login#postform" target="_blank">support forum</a>.</p>';
|
211 |
$out .= '<table class="form-table">';
|
212 |
$out .= '<tr valign="top">';
|
213 |
$out .= '<th scope="row">Networkwide default</th>';
|
@@ -216,23 +160,19 @@ if ( defined( 'ABSPATH' )
|
|
216 |
$out .= '</table>';
|
217 |
|
218 |
echo $out;
|
219 |
-
|
220 |
}
|
221 |
|
222 |
public function update_wpmu_options() {
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
update_site_option( 'rwl_page', $rwl_page );
|
229 |
-
|
230 |
}
|
231 |
-
|
232 |
}
|
233 |
|
234 |
public function admin_init() {
|
235 |
-
|
236 |
global $pagenow;
|
237 |
|
238 |
add_settings_section(
|
@@ -250,297 +190,191 @@ if ( defined( 'ABSPATH' )
|
|
250 |
'rename-wp-login-section'
|
251 |
);
|
252 |
|
253 |
-
if ( isset( $_POST['rwl_page'] )
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
if ( is_multisite() && $rwl_page === get_site_option( 'rwl_page', 'login' ) ) {
|
261 |
-
|
262 |
delete_option( 'rwl_page' );
|
263 |
-
|
264 |
-
}
|
265 |
-
|
266 |
-
else {
|
267 |
-
|
268 |
update_option( 'rwl_page', $rwl_page );
|
269 |
-
|
270 |
}
|
271 |
-
|
272 |
}
|
273 |
-
|
274 |
}
|
275 |
|
276 |
if ( get_option( 'rwl_redirect' ) ) {
|
277 |
-
|
278 |
delete_option( 'rwl_redirect' );
|
279 |
|
280 |
-
if ( is_multisite()
|
281 |
-
&& is_super_admin()
|
282 |
-
&& is_plugin_active_for_network( $this->basename() ) ) {
|
283 |
-
|
284 |
$redirect = network_admin_url( 'settings.php#rwl-page-input' );
|
285 |
-
|
286 |
-
}
|
287 |
-
|
288 |
-
else {
|
289 |
-
|
290 |
$redirect = admin_url( 'options-permalink.php#rwl-page-input' );
|
291 |
-
|
292 |
}
|
293 |
|
294 |
wp_safe_redirect( $redirect );
|
295 |
|
296 |
die;
|
297 |
-
|
298 |
}
|
299 |
-
|
300 |
}
|
301 |
|
302 |
public function rwl_section_desc() {
|
303 |
-
|
304 |
$out = '';
|
305 |
|
306 |
-
if (
|
307 |
-
|| is_super_admin() ) {
|
308 |
-
|
309 |
-
$out .= '<p>Need help? Try the <a href="http://wordpress.org/support/plugin/rename-wp-login#postform" target="_blank">support forum</a>.</p>';
|
310 |
-
|
311 |
-
}
|
312 |
-
|
313 |
-
if ( is_multisite()
|
314 |
-
&& is_super_admin()
|
315 |
-
&& is_plugin_active_for_network( $this->basename() ) ) {
|
316 |
-
|
317 |
$out .= '<p>To set a networkwide default, go to <a href="' . network_admin_url( 'settings.php#rwl-page-input' ) . '">Network Settings</a>.</p>';
|
318 |
-
|
319 |
}
|
320 |
|
321 |
echo $out;
|
322 |
-
|
323 |
}
|
324 |
|
325 |
public function rwl_page_input() {
|
326 |
-
|
327 |
if ( get_option( 'permalink_structure' ) ) {
|
328 |
-
|
329 |
echo '<code>' . trailingslashit( home_url() ) . '</code> <input id="rwl-page-input" type="text" name="rwl_page" value="' . $this->new_login_slug() . '">' . ( $this->use_trailing_slashes() ? ' <code>/</code>' : '' );
|
330 |
-
|
331 |
-
}
|
332 |
-
|
333 |
-
else {
|
334 |
-
|
335 |
echo '<code>' . trailingslashit( home_url() ) . '?</code> <input id="rwl-page-input" type="text" name="rwl_page" value="' . $this->new_login_slug() . '">';
|
336 |
-
|
337 |
}
|
338 |
-
|
339 |
}
|
340 |
|
341 |
public function admin_notices() {
|
342 |
-
|
343 |
global $pagenow;
|
344 |
|
345 |
-
$
|
346 |
-
|
347 |
-
if ( ! is_network_admin()
|
348 |
-
&& $pagenow === 'options-permalink.php'
|
349 |
-
&& isset( $_GET['settings-updated'] ) ) {
|
350 |
-
|
351 |
echo '<div class="updated"><p>Your login page is now here: <strong><a href="' . $this->new_login_url() . '">' . $this->new_login_url() . '</a></strong>. Bookmark this page!</p></div>';
|
352 |
-
|
353 |
}
|
354 |
-
|
355 |
}
|
356 |
|
357 |
public function plugin_action_links( $links ) {
|
358 |
-
|
359 |
-
if ( is_network_admin()
|
360 |
-
&& is_plugin_active_for_network( $this->basename() ) ) {
|
361 |
-
|
362 |
array_unshift( $links, '<a href="' . network_admin_url( 'settings.php#rwl-page-input' ) . '">Settings</a>' );
|
363 |
-
|
364 |
-
}
|
365 |
-
|
366 |
-
elseif ( ! is_network_admin() ) {
|
367 |
-
|
368 |
array_unshift( $links, '<a href="' . admin_url( 'options-permalink.php#rwl-page-input' ) . '">Settings</a>' );
|
369 |
-
|
370 |
}
|
371 |
|
372 |
return $links;
|
373 |
-
|
374 |
}
|
375 |
|
376 |
public function plugins_loaded() {
|
377 |
-
|
378 |
global $pagenow;
|
379 |
|
380 |
-
if (
|
381 |
-
|
382 |
-
|
383 |
-
|
|
|
|
|
384 |
wp_die( __( 'This feature is not enabled.' ) );
|
385 |
-
|
386 |
}
|
387 |
|
388 |
$request = parse_url( $_SERVER['REQUEST_URI'] );
|
389 |
|
390 |
-
if ( (
|
391 |
-
|
392 |
-
|
393 |
-
|
|
|
|
|
394 |
$this->wp_login_php = true;
|
395 |
-
|
396 |
$_SERVER['REQUEST_URI'] = $this->user_trailingslashit( '/' . str_repeat( '-/', 10 ) );
|
397 |
-
|
398 |
$pagenow = 'index.php';
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
&& empty( $_GET[$this->new_login_slug()] ) ) ) {
|
406 |
-
|
407 |
$pagenow = 'wp-login.php';
|
408 |
-
|
409 |
}
|
410 |
-
|
411 |
}
|
412 |
|
413 |
public function wp_loaded() {
|
414 |
-
|
415 |
global $pagenow;
|
416 |
|
417 |
-
if ( is_admin()
|
418 |
-
&& ! is_user_logged_in()
|
419 |
-
&& ! defined( 'DOING_AJAX' ) ) {
|
420 |
-
|
421 |
wp_die( __( 'You must log in to access the admin area.' ) );
|
422 |
-
|
423 |
}
|
424 |
|
425 |
$request = parse_url( $_SERVER['REQUEST_URI'] );
|
426 |
|
427 |
-
if (
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
die;
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
&& ( $referer = parse_url( $referer ) )
|
443 |
-
&& ! empty( $referer['query'] ) ) {
|
444 |
-
|
445 |
parse_str( $referer['query'], $referer );
|
446 |
|
447 |
-
if (
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
die;
|
457 |
-
|
458 |
}
|
459 |
-
|
460 |
}
|
461 |
|
462 |
$this->wp_template_loader();
|
463 |
-
|
464 |
-
}
|
465 |
-
|
466 |
-
elseif ( $pagenow === 'wp-login.php' ) {
|
467 |
-
|
468 |
global $error, $interim_login, $action, $user_login;
|
469 |
|
470 |
@require_once ABSPATH . 'wp-login.php';
|
471 |
|
472 |
die;
|
473 |
-
|
474 |
}
|
475 |
-
|
476 |
}
|
477 |
|
478 |
public function site_url( $url, $path, $scheme, $blog_id ) {
|
479 |
-
|
480 |
return $this->filter_wp_login_php( $url, $scheme );
|
481 |
-
|
482 |
}
|
483 |
|
484 |
public function network_site_url( $url, $path, $scheme ) {
|
485 |
-
|
486 |
return $this->filter_wp_login_php( $url, $scheme );
|
487 |
-
|
488 |
}
|
489 |
|
490 |
public function wp_redirect( $location, $status ) {
|
491 |
-
|
492 |
return $this->filter_wp_login_php( $location );
|
493 |
-
|
494 |
}
|
495 |
|
496 |
public function filter_wp_login_php( $url, $scheme = null ) {
|
497 |
-
|
498 |
if ( strpos( $url, 'wp-login.php' ) !== false ) {
|
499 |
-
|
500 |
if ( is_ssl() ) {
|
501 |
-
|
502 |
$scheme = 'https';
|
503 |
-
|
504 |
}
|
505 |
|
506 |
$args = explode( '?', $url );
|
507 |
|
508 |
if ( isset( $args[1] ) ) {
|
509 |
-
|
510 |
parse_str( $args[1], $args );
|
511 |
-
|
512 |
$url = add_query_arg( $args, $this->new_login_url( $scheme ) );
|
513 |
-
|
514 |
-
}
|
515 |
-
|
516 |
-
else {
|
517 |
-
|
518 |
$url = $this->new_login_url( $scheme );
|
519 |
-
|
520 |
}
|
521 |
-
|
522 |
}
|
523 |
|
524 |
return $url;
|
525 |
-
|
526 |
}
|
527 |
|
528 |
public function welcome_email( $value ) {
|
529 |
-
|
530 |
return $value = str_replace( 'wp-login.php', trailingslashit( get_site_option( 'rwl_page', 'login' ) ), $value );
|
531 |
-
|
532 |
}
|
533 |
|
534 |
public function forbidden_slugs() {
|
535 |
-
|
536 |
$wp = new WP;
|
537 |
-
|
538 |
return array_merge( $wp->public_query_vars, $wp->private_query_vars );
|
539 |
-
|
540 |
}
|
541 |
-
|
542 |
}
|
543 |
|
544 |
new Rename_WP_Login;
|
545 |
-
|
546 |
}
|
1 |
<?php
|
2 |
|
3 |
/*
|
4 |
+
* Plugin Name: Rename wp-login.php (unsupported)
|
5 |
+
* Plugin URI: http://wordpress.org/plugins/rename-wp-login/
|
6 |
+
* Description: Change wp-login.php to whatever you want.
|
7 |
+
* Version: 2.5.3
|
8 |
+
* Author: iseulde
|
9 |
+
* Author URI: http://profiles.wordpress.org/iseulde/
|
10 |
+
* Text Domain:
|
11 |
+
* Domain Path:
|
12 |
+
* Network:
|
13 |
+
* License: GPL-2.0+
|
14 |
+
*/
|
15 |
+
|
16 |
+
if ( defined( 'ABSPATH' ) && ! class_exists( 'Rename_WP_Login' ) ) {
|
17 |
|
18 |
class Rename_WP_Login {
|
|
|
19 |
private $wp_login_php;
|
20 |
|
21 |
private function basename() {
|
|
|
22 |
return plugin_basename( __FILE__ );
|
|
|
23 |
}
|
24 |
|
25 |
private function path() {
|
|
|
26 |
return trailingslashit( dirname( __FILE__ ) );
|
|
|
27 |
}
|
28 |
|
29 |
private function use_trailing_slashes() {
|
30 |
+
return '/' === substr( get_option( 'permalink_structure' ), -1, 1 );
|
|
|
|
|
31 |
}
|
32 |
|
33 |
private function user_trailingslashit( $string ) {
|
34 |
+
return $this->use_trailing_slashes() ? trailingslashit( $string ) : untrailingslashit( $string );
|
|
|
|
|
|
|
|
|
35 |
}
|
36 |
|
37 |
private function wp_template_loader() {
|
|
|
38 |
global $pagenow;
|
39 |
|
40 |
$pagenow = 'index.php';
|
41 |
|
42 |
if ( ! defined( 'WP_USE_THEMES' ) ) {
|
|
|
43 |
define( 'WP_USE_THEMES', true );
|
|
|
44 |
}
|
45 |
|
46 |
wp();
|
47 |
|
48 |
if ( $_SERVER['REQUEST_URI'] === $this->user_trailingslashit( str_repeat( '-/', 10 ) ) ) {
|
|
|
49 |
$_SERVER['REQUEST_URI'] = $this->user_trailingslashit( '/wp-login-php/' );
|
|
|
50 |
}
|
51 |
|
52 |
require_once( ABSPATH . WPINC . '/template-loader.php' );
|
53 |
|
54 |
die;
|
|
|
55 |
}
|
56 |
|
57 |
private function new_login_slug() {
|
58 |
+
if (
|
59 |
+
( $slug = get_option( 'rwl_page' ) ) || (
|
60 |
+
is_multisite() &&
|
61 |
+
is_plugin_active_for_network( $this->basename() ) &&
|
62 |
+
( $slug = get_site_option( 'rwl_page', 'login' ) )
|
63 |
+
) ||
|
64 |
+
( $slug = 'login' )
|
65 |
+
) {
|
66 |
return $slug;
|
|
|
67 |
}
|
|
|
68 |
}
|
69 |
|
70 |
public function new_login_url( $scheme = null ) {
|
|
|
71 |
if ( get_option( 'permalink_structure' ) ) {
|
|
|
72 |
return $this->user_trailingslashit( home_url( '/', $scheme ) . $this->new_login_slug() );
|
73 |
+
} else {
|
|
|
|
|
|
|
|
|
74 |
return home_url( '/', $scheme ) . '?' . $this->new_login_slug();
|
|
|
75 |
}
|
|
|
76 |
}
|
77 |
|
78 |
public function __construct() {
|
|
|
79 |
global $wp_version;
|
80 |
|
81 |
if ( version_compare( $wp_version, '4.0-RC1-src', '<' ) ) {
|
|
|
82 |
add_action( 'admin_notices', array( $this, 'admin_notices_incompatible' ) );
|
83 |
add_action( 'network_admin_notices', array( $this, 'admin_notices_incompatible' ) );
|
84 |
|
85 |
return;
|
|
|
86 |
}
|
87 |
|
88 |
register_activation_hook( $this->basename(), array( $this, 'activate' ) );
|
92 |
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
|
93 |
add_action( 'network_admin_notices', array( $this, 'admin_notices' ) );
|
94 |
|
95 |
+
if ( is_multisite() && ! function_exists( 'is_plugin_active_for_network' ) ) {
|
|
|
|
|
96 |
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
|
|
97 |
}
|
98 |
|
99 |
add_filter( 'plugin_action_links_' . $this->basename(), array( $this, 'plugin_action_links' ) );
|
100 |
|
101 |
+
if ( is_multisite() && is_plugin_active_for_network( $this->basename() ) ) {
|
|
|
|
|
102 |
add_filter( 'network_admin_plugin_action_links_' . $this->basename(), array( $this, 'plugin_action_links' ) );
|
103 |
|
104 |
add_action( 'wpmu_options', array( $this, 'wpmu_options' ) );
|
105 |
add_action( 'update_wpmu_options', array( $this, 'update_wpmu_options' ) );
|
|
|
106 |
}
|
107 |
|
108 |
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 1 );
|
115 |
add_filter( 'site_option_welcome_email', array( $this, 'welcome_email' ) );
|
116 |
|
117 |
remove_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 );
|
|
|
118 |
}
|
119 |
|
120 |
public function admin_notices_incompatible() {
|
|
|
121 |
echo '<div class="error"><p>Please upgrade to the latest version of WordPress to activate <strong>Rename wp-login.php</strong>.</p></div>';
|
|
|
122 |
}
|
123 |
|
124 |
public function activate() {
|
|
|
125 |
add_option( 'rwl_redirect', '1' );
|
|
|
126 |
delete_option( 'rwl_admin' );
|
|
|
127 |
}
|
128 |
|
129 |
public static function uninstall() {
|
|
|
130 |
global $wpdb;
|
131 |
|
132 |
if ( is_multisite() ) {
|
|
|
133 |
$blogs = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" );
|
134 |
|
135 |
+
if ( $blogs ) {
|
136 |
+
foreach ( $blogs as $blog ) {
|
137 |
+
switch_to_blog( $blog );
|
138 |
+
delete_option( 'rwl_page' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
}
|
140 |
|
141 |
+
restore_current_blog();
|
142 |
+
}
|
|
|
|
|
|
|
143 |
|
144 |
+
delete_site_option( 'rwl_page' );
|
145 |
+
} else {
|
146 |
delete_option( 'rwl_page' );
|
|
|
147 |
}
|
|
|
148 |
}
|
149 |
|
150 |
public function wpmu_options() {
|
|
|
151 |
$out = '';
|
152 |
|
153 |
$out .= '<h3>Rename wp-login.php</h3>';
|
154 |
$out .= '<p>This option allows you to set a networkwide default, which can be overridden by individual sites. Simply go to to the site’s permalink settings to change the url.</p>';
|
|
|
155 |
$out .= '<table class="form-table">';
|
156 |
$out .= '<tr valign="top">';
|
157 |
$out .= '<th scope="row">Networkwide default</th>';
|
160 |
$out .= '</table>';
|
161 |
|
162 |
echo $out;
|
|
|
163 |
}
|
164 |
|
165 |
public function update_wpmu_options() {
|
166 |
+
if (
|
167 |
+
( $rwl_page = sanitize_title_with_dashes( $_POST['rwl_page'] ) ) &&
|
168 |
+
strpos( $rwl_page, 'wp-login' ) === false &&
|
169 |
+
! in_array( $rwl_page, $this->forbidden_slugs() )
|
170 |
+
) {
|
171 |
update_site_option( 'rwl_page', $rwl_page );
|
|
|
172 |
}
|
|
|
173 |
}
|
174 |
|
175 |
public function admin_init() {
|
|
|
176 |
global $pagenow;
|
177 |
|
178 |
add_settings_section(
|
190 |
'rename-wp-login-section'
|
191 |
);
|
192 |
|
193 |
+
if ( isset( $_POST['rwl_page'] ) && $pagenow === 'options-permalink.php' ) {
|
194 |
+
if (
|
195 |
+
( $rwl_page = sanitize_title_with_dashes( $_POST['rwl_page'] ) ) &&
|
196 |
+
strpos( $rwl_page, 'wp-login' ) === false &&
|
197 |
+
! in_array( $rwl_page, $this->forbidden_slugs() )
|
198 |
+
) {
|
|
|
199 |
if ( is_multisite() && $rwl_page === get_site_option( 'rwl_page', 'login' ) ) {
|
|
|
200 |
delete_option( 'rwl_page' );
|
201 |
+
} else {
|
|
|
|
|
|
|
|
|
202 |
update_option( 'rwl_page', $rwl_page );
|
|
|
203 |
}
|
|
|
204 |
}
|
|
|
205 |
}
|
206 |
|
207 |
if ( get_option( 'rwl_redirect' ) ) {
|
|
|
208 |
delete_option( 'rwl_redirect' );
|
209 |
|
210 |
+
if ( is_multisite() && is_super_admin() && is_plugin_active_for_network( $this->basename() ) ) {
|
|
|
|
|
|
|
211 |
$redirect = network_admin_url( 'settings.php#rwl-page-input' );
|
212 |
+
} else {
|
|
|
|
|
|
|
|
|
213 |
$redirect = admin_url( 'options-permalink.php#rwl-page-input' );
|
|
|
214 |
}
|
215 |
|
216 |
wp_safe_redirect( $redirect );
|
217 |
|
218 |
die;
|
|
|
219 |
}
|
|
|
220 |
}
|
221 |
|
222 |
public function rwl_section_desc() {
|
|
|
223 |
$out = '';
|
224 |
|
225 |
+
if ( is_multisite() && is_super_admin() && is_plugin_active_for_network( $this->basename() ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
$out .= '<p>To set a networkwide default, go to <a href="' . network_admin_url( 'settings.php#rwl-page-input' ) . '">Network Settings</a>.</p>';
|
|
|
227 |
}
|
228 |
|
229 |
echo $out;
|
|
|
230 |
}
|
231 |
|
232 |
public function rwl_page_input() {
|
|
|
233 |
if ( get_option( 'permalink_structure' ) ) {
|
|
|
234 |
echo '<code>' . trailingslashit( home_url() ) . '</code> <input id="rwl-page-input" type="text" name="rwl_page" value="' . $this->new_login_slug() . '">' . ( $this->use_trailing_slashes() ? ' <code>/</code>' : '' );
|
235 |
+
} else {
|
|
|
|
|
|
|
|
|
236 |
echo '<code>' . trailingslashit( home_url() ) . '?</code> <input id="rwl-page-input" type="text" name="rwl_page" value="' . $this->new_login_slug() . '">';
|
|
|
237 |
}
|
|
|
238 |
}
|
239 |
|
240 |
public function admin_notices() {
|
|
|
241 |
global $pagenow;
|
242 |
|
243 |
+
if ( ! is_network_admin() && $pagenow === 'options-permalink.php' && isset( $_GET['settings-updated'] ) ) {
|
|
|
|
|
|
|
|
|
|
|
244 |
echo '<div class="updated"><p>Your login page is now here: <strong><a href="' . $this->new_login_url() . '">' . $this->new_login_url() . '</a></strong>. Bookmark this page!</p></div>';
|
|
|
245 |
}
|
|
|
246 |
}
|
247 |
|
248 |
public function plugin_action_links( $links ) {
|
249 |
+
if ( is_network_admin() && is_plugin_active_for_network( $this->basename() ) ) {
|
|
|
|
|
|
|
250 |
array_unshift( $links, '<a href="' . network_admin_url( 'settings.php#rwl-page-input' ) . '">Settings</a>' );
|
251 |
+
} elseif ( ! is_network_admin() ) {
|
|
|
|
|
|
|
|
|
252 |
array_unshift( $links, '<a href="' . admin_url( 'options-permalink.php#rwl-page-input' ) . '">Settings</a>' );
|
|
|
253 |
}
|
254 |
|
255 |
return $links;
|
|
|
256 |
}
|
257 |
|
258 |
public function plugins_loaded() {
|
|
|
259 |
global $pagenow;
|
260 |
|
261 |
+
if (
|
262 |
+
! is_multisite() && (
|
263 |
+
strpos( $_SERVER['REQUEST_URI'], 'wp-signup' ) !== false ||
|
264 |
+
strpos( $_SERVER['REQUEST_URI'], 'wp-activate' ) !== false
|
265 |
+
)
|
266 |
+
) {
|
267 |
wp_die( __( 'This feature is not enabled.' ) );
|
|
|
268 |
}
|
269 |
|
270 |
$request = parse_url( $_SERVER['REQUEST_URI'] );
|
271 |
|
272 |
+
if ( (
|
273 |
+
strpos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false ||
|
274 |
+
untrailingslashit( $request['path'] ) === site_url( 'wp-login', 'relative' )
|
275 |
+
) &&
|
276 |
+
! is_admin()
|
277 |
+
) {
|
278 |
$this->wp_login_php = true;
|
|
|
279 |
$_SERVER['REQUEST_URI'] = $this->user_trailingslashit( '/' . str_repeat( '-/', 10 ) );
|
|
|
280 |
$pagenow = 'index.php';
|
281 |
+
} elseif (
|
282 |
+
untrailingslashit( $request['path'] ) === home_url( $this->new_login_slug(), 'relative' ) || (
|
283 |
+
! get_option( 'permalink_structure' ) &&
|
284 |
+
isset( $_GET[$this->new_login_slug()] ) &&
|
285 |
+
empty( $_GET[$this->new_login_slug()] )
|
286 |
+
) ) {
|
|
|
|
|
287 |
$pagenow = 'wp-login.php';
|
|
|
288 |
}
|
|
|
289 |
}
|
290 |
|
291 |
public function wp_loaded() {
|
|
|
292 |
global $pagenow;
|
293 |
|
294 |
+
if ( is_admin() && ! is_user_logged_in() && ! defined( 'DOING_AJAX' ) ) {
|
|
|
|
|
|
|
295 |
wp_die( __( 'You must log in to access the admin area.' ) );
|
|
|
296 |
}
|
297 |
|
298 |
$request = parse_url( $_SERVER['REQUEST_URI'] );
|
299 |
|
300 |
+
if (
|
301 |
+
$pagenow === 'wp-login.php' &&
|
302 |
+
$request['path'] !== $this->user_trailingslashit( $request['path'] ) &&
|
303 |
+
get_option( 'permalink_structure' )
|
304 |
+
) {
|
305 |
+
wp_safe_redirect( $this->user_trailingslashit( $this->new_login_url() ) . ( ! empty( $_SERVER['QUERY_STRING'] ) ? '?' . $_SERVER['QUERY_STRING'] : '' ) );
|
|
|
306 |
die;
|
307 |
+
} elseif ( $this->wp_login_php ) {
|
308 |
+
if (
|
309 |
+
( $referer = wp_get_referer() ) &&
|
310 |
+
strpos( $referer, 'wp-activate.php' ) !== false &&
|
311 |
+
( $referer = parse_url( $referer ) ) &&
|
312 |
+
! empty( $referer['query'] )
|
313 |
+
) {
|
|
|
|
|
|
|
314 |
parse_str( $referer['query'], $referer );
|
315 |
|
316 |
+
if (
|
317 |
+
! empty( $referer['key'] ) &&
|
318 |
+
( $result = wpmu_activate_signup( $referer['key'] ) ) &&
|
319 |
+
is_wp_error( $result ) && (
|
320 |
+
$result->get_error_code() === 'already_active' ||
|
321 |
+
$result->get_error_code() === 'blog_taken'
|
322 |
+
) ) {
|
323 |
+
wp_safe_redirect( $this->new_login_url() . ( ! empty( $_SERVER['QUERY_STRING'] ) ? '?' . $_SERVER['QUERY_STRING'] : '' ) );
|
|
|
324 |
die;
|
|
|
325 |
}
|
|
|
326 |
}
|
327 |
|
328 |
$this->wp_template_loader();
|
329 |
+
} elseif ( $pagenow === 'wp-login.php' ) {
|
|
|
|
|
|
|
|
|
330 |
global $error, $interim_login, $action, $user_login;
|
331 |
|
332 |
@require_once ABSPATH . 'wp-login.php';
|
333 |
|
334 |
die;
|
|
|
335 |
}
|
|
|
336 |
}
|
337 |
|
338 |
public function site_url( $url, $path, $scheme, $blog_id ) {
|
|
|
339 |
return $this->filter_wp_login_php( $url, $scheme );
|
|
|
340 |
}
|
341 |
|
342 |
public function network_site_url( $url, $path, $scheme ) {
|
|
|
343 |
return $this->filter_wp_login_php( $url, $scheme );
|
|
|
344 |
}
|
345 |
|
346 |
public function wp_redirect( $location, $status ) {
|
|
|
347 |
return $this->filter_wp_login_php( $location );
|
|
|
348 |
}
|
349 |
|
350 |
public function filter_wp_login_php( $url, $scheme = null ) {
|
|
|
351 |
if ( strpos( $url, 'wp-login.php' ) !== false ) {
|
|
|
352 |
if ( is_ssl() ) {
|
|
|
353 |
$scheme = 'https';
|
|
|
354 |
}
|
355 |
|
356 |
$args = explode( '?', $url );
|
357 |
|
358 |
if ( isset( $args[1] ) ) {
|
|
|
359 |
parse_str( $args[1], $args );
|
|
|
360 |
$url = add_query_arg( $args, $this->new_login_url( $scheme ) );
|
361 |
+
} else {
|
|
|
|
|
|
|
|
|
362 |
$url = $this->new_login_url( $scheme );
|
|
|
363 |
}
|
|
|
364 |
}
|
365 |
|
366 |
return $url;
|
|
|
367 |
}
|
368 |
|
369 |
public function welcome_email( $value ) {
|
|
|
370 |
return $value = str_replace( 'wp-login.php', trailingslashit( get_site_option( 'rwl_page', 'login' ) ), $value );
|
|
|
371 |
}
|
372 |
|
373 |
public function forbidden_slugs() {
|
|
|
374 |
$wp = new WP;
|
|
|
375 |
return array_merge( $wp->public_query_vars, $wp->private_query_vars );
|
|
|
376 |
}
|
|
|
377 |
}
|
378 |
|
379 |
new Rename_WP_Login;
|
|
|
380 |
}
|