Rename wp-login.php - Version 2.2

Version Description

  • Fixed issue where requests redirect to the new login page.
  • Trailing slash based on the permalink structure.
Download this release

Release Info

Developer avryl
Plugin Icon 128x128 Rename wp-login.php
Version 2.2
Comparing to
See all releases

Code changes from version 2.1.1 to 2.2

Files changed (3) hide show
  1. readme.md +6 -1
  2. readme.txt +6 -1
  3. rename-wp-login.php +77 -48
readme.md CHANGED
@@ -4,7 +4,7 @@
4
  **Tags:** rename, login, wp-login, wp-login.php, brute force attacks, custom login url, security
5
  **Requires at least:** 3.8
6
  **Tested up to:** 3.8
7
- **Stable tag:** 2.1.1
8
  **License:** GPLv2 or later
9
  **License URI:** http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -55,6 +55,11 @@ Either go to your MySQL database and look for the value of `rwl_page` in the opt
55
 
56
  ## Changelog
57
 
 
 
 
 
 
58
  ### 2.1
59
 
60
  * Works now with non-pretty permalinks!
4
  **Tags:** rename, login, wp-login, wp-login.php, brute force attacks, custom login url, security
5
  **Requires at least:** 3.8
6
  **Tested up to:** 3.8
7
+ **Stable tag:** 2.2
8
  **License:** GPLv2 or later
9
  **License URI:** http://www.gnu.org/licenses/gpl-2.0.html
10
 
55
 
56
  ## Changelog
57
 
58
+ ### 2.2
59
+
60
+ * Fixed issue where requests redirect to the new login page.
61
+ * Trailing slash based on the permalink structure.
62
+
63
  ### 2.1
64
 
65
  * Works now with non-pretty permalinks!
readme.txt CHANGED
@@ -5,7 +5,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
5
  Tags: rename, login, wp-login, wp-login.php, brute force attacks, custom login url, security
6
  Requires at least: 3.8
7
  Tested up to: 3.8
8
- Stable tag: 2.1.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -60,6 +60,11 @@ Either go to your MySQL database and look for the value of `rwl_page` in the opt
60
 
61
  == Changelog ==
62
 
 
 
 
 
 
63
  = 2.1 =
64
 
65
  * Works now with non-pretty permalinks!
5
  Tags: rename, login, wp-login, wp-login.php, brute force attacks, custom login url, security
6
  Requires at least: 3.8
7
  Tested up to: 3.8
8
+ Stable tag: 2.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
60
 
61
  == Changelog ==
62
 
63
+ = 2.2 =
64
+
65
+ * Fixed issue where requests redirect to the new login page.
66
+ * Trailing slash based on the permalink structure.
67
+
68
  = 2.1 =
69
 
70
  * Works now with non-pretty permalinks!
rename-wp-login.php CHANGED
@@ -6,7 +6,7 @@ Plugin URI: http://wordpress.org/plugins/rename-wp-login/
6
  Description: Change wp-login.php to whatever you want. It can also prevent a lot of brute force attacks.
7
  Author: avryl
8
  Author URI: http://profiles.wordpress.org/avryl/
9
- Version: 2.1.1
10
  Text Domain: rename-wp-login
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -17,6 +17,8 @@ if ( ! class_exists( 'Rename_WP_Login' )
17
 
18
  class Rename_WP_Login {
19
 
 
 
20
  private function basename() {
21
 
22
  return plugin_basename( __FILE__ );
@@ -29,22 +31,36 @@ if ( ! class_exists( 'Rename_WP_Login' )
29
 
30
  }
31
 
32
- private function set_404() {
 
 
33
 
34
- global $wp_query;
35
 
36
- status_header( 404 );
37
 
38
- $wp_query->set_404();
 
 
39
 
40
- if ( ( ( $template = get_404_template() )
41
- || ( $template = get_index_template() ) )
42
- && ( $template = apply_filters( 'template_include', $template ) ) ) {
 
 
43
 
44
- include( $template );
 
 
 
 
45
 
46
  }
47
 
 
 
 
 
48
  die;
49
 
50
  }
@@ -67,7 +83,7 @@ if ( ! class_exists( 'Rename_WP_Login' )
67
 
68
  if ( get_option( 'permalink_structure' ) ) {
69
 
70
- return trailingslashit( trailingslashit( home_url() ) . $this->new_login_slug() );
71
 
72
  }
73
 
@@ -117,13 +133,13 @@ if ( ! class_exists( 'Rename_WP_Login' )
117
  add_action( 'update_wpmu_options', array( $this, 'update_wpmu_options' ) );
118
 
119
  }
 
 
 
120
 
121
- add_action( 'wp_loaded', array( $this, 'init' ) );
122
- add_action( 'login_init', array( $this, 'login_init' ) );
123
-
124
- add_filter( 'site_url', array( $this, 'site_url' ), 10, 2 );
125
- add_filter( 'network_site_url', array( $this, 'site_url' ), 10, 2 );
126
- add_filter( 'wp_redirect', array( $this, 'wp_redirect' ), 10, 2 );
127
 
128
  add_filter( 'site_option_welcome_email', array( $this, 'welcome_email' ) );
129
 
@@ -301,10 +317,10 @@ if ( ! class_exists( 'Rename_WP_Login' )
301
  }
302
 
303
  public function rwl_page_input() {
304
-
305
  if ( get_option( 'permalink_structure' ) ) {
306
 
307
- echo '<code>' . trailingslashit( home_url() ) . '</code> <input id="rwl-page-input" type="text" name="rwl_page" value="' . $this->new_login_slug() . '"> <code>/</code>';
308
 
309
  }
310
 
@@ -375,15 +391,9 @@ if ( ! class_exists( 'Rename_WP_Login' )
375
 
376
  }
377
 
378
- public function init() {
379
 
380
- if ( is_admin()
381
- && ! is_user_logged_in()
382
- && ! defined( 'DOING_AJAX' ) ) {
383
-
384
- wp_die( __( 'You must log in to access the admin area.' ) );
385
-
386
- }
387
 
388
  if ( ! is_multisite()
389
  && ( strpos( $_SERVER['REQUEST_URI'], 'wp-signup' ) !== false
@@ -395,31 +405,52 @@ if ( ! class_exists( 'Rename_WP_Login' )
395
 
396
  $request = parse_url( $_SERVER['REQUEST_URI'] );
397
 
398
- if ( $request['path'] === home_url( $this->new_login_slug(), 'relative' ) ) {
399
-
400
- wp_safe_redirect( $this->new_login_url() . ( ! empty( $_SERVER['QUERY_STRING'] ) ? '?' . $_SERVER['QUERY_STRING'] : '' ) );
401
 
402
- die;
 
 
 
 
403
 
404
  }
405
 
406
- if ( untrailingslashit( $request['path'] ) === home_url( $this->new_login_slug(), 'relative' )
407
  || ( ! get_option( 'permalink_structure' )
408
- && isset( $_GET[$this->new_login_slug()] ) ) ) {
 
409
 
410
- status_header( 200 );
411
 
412
- require_once( $this->path() . 'rwl-login.php' );
413
 
414
- die;
 
 
 
 
 
 
 
 
 
 
415
 
416
  }
417
 
418
- }
419
 
420
- public function login_init() {
 
421
 
422
- if ( strpos( $_SERVER['REQUEST_URI'], 'wp-login' ) !== false ) {
 
 
 
 
 
 
 
423
 
424
  if ( ( $referer = wp_get_referer() )
425
  && strpos( $referer, 'wp-activate.php' ) !== false
@@ -434,7 +465,8 @@ if ( ! class_exists( 'Rename_WP_Login' )
434
  && ( $result->get_error_code() === 'already_active'
435
  || $result->get_error_code() === 'blog_taken' ) ) {
436
 
437
- wp_safe_redirect( $this->new_login_url() . ( ! empty( $_SERVER['QUERY_STRING'] ) ? '?' . $_SERVER['QUERY_STRING'] : '' ) );
 
438
 
439
  die;
440
 
@@ -442,21 +474,18 @@ if ( ! class_exists( 'Rename_WP_Login' )
442
 
443
  }
444
 
445
- $this->set_404();
446
 
447
  }
448
 
449
- }
450
-
451
- public function site_url( $url, $path ) {
452
 
453
- return $this->filter_wp_login_php( $url );
454
 
455
- }
456
 
457
- public function wp_redirect( $location, $status ) {
458
 
459
- return $this->filter_wp_login_php( $location );
460
 
461
  }
462
 
@@ -488,7 +517,7 @@ if ( ! class_exists( 'Rename_WP_Login' )
488
 
489
  public function welcome_email( $value ) {
490
 
491
- return $value = preg_replace( '/(BLOG_URL)([\w\-]+)(\.php)/', 'BLOG_URL' . trailingslashit( get_site_option( 'rwl_page', 'login' ) ), $value );
492
 
493
  }
494
 
6
  Description: Change wp-login.php to whatever you want. It can also prevent a lot of brute force attacks.
7
  Author: avryl
8
  Author URI: http://profiles.wordpress.org/avryl/
9
+ Version: 2.2
10
  Text Domain: rename-wp-login
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
17
 
18
  class Rename_WP_Login {
19
 
20
+ private $wp_login_php;
21
+
22
  private function basename() {
23
 
24
  return plugin_basename( __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
+ require_once( ABSPATH . WPINC . '/template-loader.php' );
63
+
64
  die;
65
 
66
  }
83
 
84
  if ( get_option( 'permalink_structure' ) ) {
85
 
86
+ return $this->user_trailingslashit( trailingslashit( home_url() ) . $this->new_login_slug() );
87
 
88
  }
89
 
133
  add_action( 'update_wpmu_options', array( $this, 'update_wpmu_options' ) );
134
 
135
  }
136
+
137
+ add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 1 );
138
+ add_action( 'wp_loaded', array( $this, 'wp_loaded' ) );
139
 
140
+ add_filter( 'site_url', array( $this, 'filter_wp_login_php' ) );
141
+ add_filter( 'network_site_url', array( $this, 'filter_wp_login_php' ) );
142
+ add_filter( 'wp_redirect', array( $this, 'filter_wp_login_php' ) );
 
 
 
143
 
144
  add_filter( 'site_option_welcome_email', array( $this, 'welcome_email' ) );
145
 
317
  }
318
 
319
  public function rwl_page_input() {
320
+
321
  if ( get_option( 'permalink_structure' ) ) {
322
 
323
+ 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>' : '' );
324
 
325
  }
326
 
391
 
392
  }
393
 
394
+ public function plugins_loaded() {
395
 
396
+ global $pagenow;
 
 
 
 
 
 
397
 
398
  if ( ! is_multisite()
399
  && ( strpos( $_SERVER['REQUEST_URI'], 'wp-signup' ) !== false
405
 
406
  $request = parse_url( $_SERVER['REQUEST_URI'] );
407
 
408
+ if ( strpos( $_SERVER['REQUEST_URI'], 'wp-login' ) !== false ) {
 
 
409
 
410
+ $this->wp_login_php = true;
411
+
412
+ $_SERVER['REQUEST_URI'] = str_repeat( '-/', 10 );
413
+
414
+ $pagenow = 'index.php';
415
 
416
  }
417
 
418
+ elseif ( untrailingslashit( $request['path'] ) === home_url( $this->new_login_slug(), 'relative' )
419
  || ( ! get_option( 'permalink_structure' )
420
+ && isset( $_GET[$this->new_login_slug()] )
421
+ && empty( $_GET[$this->new_login_slug()] ) ) ) {
422
 
423
+ $pagenow = 'wp-login.php';
424
 
425
+ }
426
 
427
+ }
428
+
429
+ public function wp_loaded() {
430
+
431
+ global $pagenow;
432
+
433
+ if ( is_admin()
434
+ && ! is_user_logged_in()
435
+ && ! defined( 'DOING_AJAX' ) ) {
436
+
437
+ wp_die( __( 'You must log in to access the admin area.' ) );
438
 
439
  }
440
 
441
+ $request = parse_url( $_SERVER['REQUEST_URI'] );
442
 
443
+ if ( $pagenow === 'wp-login.php'
444
+ && $request['path'] !== $this->user_trailingslashit( $request['path'] ) ) {
445
 
446
+ wp_safe_redirect( $this->user_trailingslashit( $this->new_login_url() )
447
+ . ( ! empty( $_SERVER['QUERY_STRING'] ) ? '?' . $_SERVER['QUERY_STRING'] : '' ) );
448
+
449
+ die;
450
+
451
+ }
452
+
453
+ elseif ( $this->wp_login_php ) {
454
 
455
  if ( ( $referer = wp_get_referer() )
456
  && strpos( $referer, 'wp-activate.php' ) !== false
465
  && ( $result->get_error_code() === 'already_active'
466
  || $result->get_error_code() === 'blog_taken' ) ) {
467
 
468
+ wp_safe_redirect( $this->new_login_url()
469
+ . ( ! empty( $_SERVER['QUERY_STRING'] ) ? '?' . $_SERVER['QUERY_STRING'] : '' ) );
470
 
471
  die;
472
 
474
 
475
  }
476
 
477
+ $this->wp_template_loader();
478
 
479
  }
480
 
481
+ elseif ( $pagenow === 'wp-login.php' ) {
 
 
482
 
483
+ require_once( $this->path() . 'rwl-login.php' );
484
 
485
+ die;
486
 
 
487
 
488
+ }
489
 
490
  }
491
 
517
 
518
  public function welcome_email( $value ) {
519
 
520
+ return $value = str_replace( 'wp-login.php', trailingslashit( get_site_option( 'rwl_page', 'login' ) ), $value );
521
 
522
  }
523