class-activation.php
3 years ago
class-admin-interface.php
3 years ago
class-content-management.php
3 years ago
class-deactivation.php
3 years ago
class-security.php
3 years ago
class-utilities.php
3 years ago
class-security.php
72 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ASENHA\Classes; |
| 4 | |
| 5 | /** |
| 6 | * Class related to Security features |
| 7 | * |
| 8 | * @since 1.4.0 |
| 9 | */ |
| 10 | class Security { |
| 11 | |
| 12 | /** |
| 13 | * Redirect to /not_found when login URL does not contain the custom login slug |
| 14 | * |
| 15 | * @link https://plugins.trac.wordpress.org/browser/admin-login-url-change/trunk/admin-login-url-change.php#L121 |
| 16 | * @since 1.4.0 |
| 17 | */ |
| 18 | public function redirect_on_default_login_urls() { |
| 19 | |
| 20 | $options = get_option( ASENHA_SLUG_U ); |
| 21 | $custom_login_slug = $options['custom_login_slug']; |
| 22 | $url_input = sanitize_text_field( $_SERVER['REQUEST_URI'] ); |
| 23 | |
| 24 | // Custom login slug is not part of the login URL typed into the browser |
| 25 | // e.g. https://www.example.com/wp-admin/ or https://www.example.com/wp-login.php |
| 26 | if ( false === strpos( $url_input, $custom_login_slug ) ) { |
| 27 | |
| 28 | wp_safe_redirect( home_url( 'not_found/' ), 302 ); |
| 29 | exit(); |
| 30 | |
| 31 | } |
| 32 | |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Redirect to valid login URL when custom login slug is part of the request URL |
| 37 | * |
| 38 | * @link https://plugins.trac.wordpress.org/browser/admin-login-url-change/trunk/admin-login-url-change.php#L134 |
| 39 | * @since 1.4.0 |
| 40 | */ |
| 41 | public function redirect_on_custom_login_url() { |
| 42 | |
| 43 | $options = get_option( ASENHA_SLUG_U ); |
| 44 | $custom_login_slug = $options['custom_login_slug']; |
| 45 | $url_input = parse_url( sanitize_text_field( $_SERVER['REQUEST_URI'] ) ); // an array |
| 46 | |
| 47 | if ( ( $url_input['path'] == '/' . $custom_login_slug ) || ( $url_input['path'] == '/' . $custom_login_slug . '/' ) ) { |
| 48 | |
| 49 | wp_safe_redirect( home_url( 'wp-login.php?' . $custom_login_slug . '&redirect=false' ) ); |
| 50 | exit(); |
| 51 | |
| 52 | } |
| 53 | |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Redirect on successful logout |
| 58 | * |
| 59 | * @link https://plugins.trac.wordpress.org/browser/admin-login-url-change/trunk/admin-login-url-change.php#L148 |
| 60 | * @since 1.4.0 |
| 61 | */ |
| 62 | public function redirect_to_custom_login_url() { |
| 63 | |
| 64 | $options = get_option( ASENHA_SLUG_U ); |
| 65 | $custom_login_slug = $options['custom_login_slug']; |
| 66 | |
| 67 | wp_safe_redirect( home_url( 'wp-login.php?' . $custom_login_slug . '&redirect=false' ) ); |
| 68 | exit(); |
| 69 | |
| 70 | } |
| 71 | |
| 72 | } |