Plugin Directory

Changeset 3434007


Ignore:
Timestamp:
01/07/2026 02:02:45 AM (3 months ago)
Author:
nhrrob
Message:

Update to version 1.0.3 from GitHub

Location:
nhrrob-secure
Files:
3 added
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • nhrrob-secure/tags/1.0.3/nhrrob-secure.php

    r3410319 r3434007  
    11<?php
    22/**
    3  * Plugin Name: NHR Secure | Protect Admin Area
     3 * Plugin Name: NHR Secure | Protect Admin, Debug Logs & Limit Logins
    44 * Plugin URI: http://wordpress.org/plugins/nhrrob-secure/
    55 * Description: Lightweight WordPress security plugin that protects your admin area, hides debug logs, and limits login attempts. Minimal code, maximum protection.
    66 * Author: Nazmul Hasan Robin
    77 * Author URI: https://profiles.wordpress.org/nhrrob/
    8  * Version: 1.0.2
     8 * Version: 1.0.3
    99 * Requires at least: 6.0
    1010 * Requires PHP: 7.4
     
    1616if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    1717
    18 define( 'NHRROB_SECURE_VERSION', '1.0.2' );
     18define( 'NHRROB_SECURE_VERSION', '1.0.3' );
    1919define( 'NHRROB_SECURE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
    2020
     
    2222 * Feature List
    2323 * 1. Limit Login Attempts
    24  * 2. Protect Sensitive Files (debug.log)
     24 * 2. Custom Login Page (/hidden-access-52w instead of /wp-login.php)
     25 * 3. Protect Sensitive Files (debug.log)
    2526 */
    2627
     
    7879
    7980/**
     81 * ============================
     82 * Helper: Render 404 Page
     83 * ============================
     84 */
     85function nhrrob_secure_render_404() {
     86    wp_safe_redirect( home_url( '404' ) );
     87    exit;
     88}
     89
     90/**
    8091 * ============================================================
    8192 * 1. LIMIT LOGIN ATTEMPTS (IP + Username)
     
    136147
    137148/**
     149 * ============================================================
     150 * 2. CUSTOM LOGIN PAGE
     151 * ============================================================
     152 *
     153 * Changes default login URL from /wp-login.php to /hidden-access-52w
     154 *
     155 * Usage:
     156 * - Change the custom login URL:
     157 *   add_filter( 'nhrrob_secure_custom_login_url', fn() => '/my-custom-login' );
     158 * - Turn off the feature:
     159 *   add_filter( 'nhrrob_secure_custom_login_page', '__return_false' );
     160 */
     161function nhrrob_secure_custom_login_page_init() {
     162    if ( ! apply_filters( 'nhrrob_secure_custom_login_page', true ) ) {
     163        return;
     164    }
     165
     166    // Block direct access to wp-login.php
     167    $script_name = isset( $_SERVER['SCRIPT_NAME'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SCRIPT_NAME'] ) ) : '';
     168    if ( strpos( $script_name, '/wp-login.php' ) !== false ) {
     169        nhrrob_secure_render_404();
     170    }
     171   
     172    // Block direct access to wp-admin for guests
     173    add_action( 'init', function() {
     174        $script_name = isset( $_SERVER['SCRIPT_NAME'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SCRIPT_NAME'] ) ) : '';
     175       
     176        if ( is_admin() && ! is_user_logged_in() && ! defined( 'DOING_AJAX' ) && ! defined( 'DOING_CRON' ) ) {
     177             // Allow admin-post.php for frontend form submissions
     178             if ( strpos( $script_name, 'admin-post.php' ) === false ) {
     179                 nhrrob_secure_render_404();
     180             }
     181        }
     182    });
     183
     184    // Handle custom login URL (use template_redirect for proper WordPress context)
     185    add_action( 'template_redirect', function() {
     186        $custom_login_url = apply_filters( 'nhrrob_secure_custom_login_url', '/hidden-access-52w' );
     187        $custom_login_url = trim( $custom_login_url, '/' );
     188        $custom_login_url = '/' . ltrim( $custom_login_url, '/' );
     189
     190        $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
     191        $parsed_url = wp_parse_url( $request_uri );
     192        $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
     193
     194        // Normalize path (remove trailing slash for comparison)
     195        $path_normalized = rtrim( $path, '/' );
     196        $custom_login_url_normalized = rtrim( $custom_login_url, '/' );
     197
     198        // Check if request is for custom login URL
     199        if ( $path_normalized === $custom_login_url_normalized || $path === $custom_login_url || $path === $custom_login_url . '/' ) {
     200            // Preserve query string
     201            $query_string = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '';
     202           
     203            // Temporarily modify REQUEST_URI to load wp-login.php
     204            $_SERVER['REQUEST_URI'] = '/wp-login.php' . $query_string;
     205           
     206            // Bring globals into scope for wp-login.php
     207            global $error, $interim_login, $action, $wp_error, $user_login;
     208           
     209            // Override 404 status (since WP thinks this slug doesn't exist)
     210            if ( function_exists( 'status_header' ) ) {
     211                status_header( 200 );
     212            }
     213            if ( function_exists( 'nocache_headers' ) ) {
     214                nocache_headers();
     215            }
     216
     217
     218           
     219            // Load WordPress login
     220            require_once( ABSPATH . 'wp-login.php' );
     221           
     222
     223           
     224            exit;
     225        }
     226    }, 1 );
     227
     228    // Rewrite wp-login.php URLs to custom login URL
     229    add_filter( 'site_url', function( $url, $path, $scheme ) {
     230        if ( strpos( $url, 'wp-login.php' ) !== false ) {
     231            $custom_login_url = apply_filters( 'nhrrob_secure_custom_login_url', '/hidden-access-52w' );
     232            $custom_login_url = trim( $custom_login_url, '/' );
     233            $url = str_replace( 'wp-login.php', $custom_login_url, $url );
     234            $url = str_replace( '//' . $custom_login_url, '/' . $custom_login_url, $url ); // fix potential double slash if any
     235        }
     236        return $url;
     237    }, 10, 3 );
     238}
     239
     240add_action( 'init', 'nhrrob_secure_custom_login_page_init', 0 );
     241
     242/**
     243 * ============================================================
     244 * 3. PROTECT DEBUG LOG FILE
     245 * ============================================================
     246 *
     247 * Blocks direct access to /wp-content/debug.log
     248 * Shows 403 Forbidden for all users
     249 *
     250 * Usage:
     251 * - Turn off the feature:
     252 *   add_filter( 'nhrrob_secure_protect_debug_log', '__return_false' );
     253 */
     254function nhrrob_secure_protect_debug_log_init() {
     255    if ( ! apply_filters( 'nhrrob_secure_protect_debug_log', true ) ) {
     256        return;
     257    }
     258
     259    // Check early to catch direct file access
     260    add_action( 'plugins_loaded', function() {
     261        $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
     262        $parsed_url = wp_parse_url( $request_uri );
     263        $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
     264
     265        // Check if request is for debug.log in wp-content directory
     266        if ( strpos( $path, '/wp-content/debug.log' ) !== false ||
     267             ( strpos( $path, 'debug.log' ) !== false && strpos( $path, 'wp-content' ) !== false ) ) {
     268            if ( function_exists( 'status_header' ) ) {
     269                status_header( 403 );
     270            } else {
     271                http_response_code( 403 );
     272            }
     273            if ( function_exists( 'nocache_headers' ) ) {
     274                nocache_headers();
     275            }
     276            header( 'Content-Type: text/html; charset=utf-8' );
     277            die( '403 Forbidden' );
     278        }
     279    }, 1 );
     280
     281    // Also check in template_redirect as backup
     282    add_action( 'template_redirect', function() {
     283        $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
     284        $parsed_url = wp_parse_url( $request_uri );
     285        $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
     286
     287        // Check if request is for debug.log in wp-content directory
     288        if ( strpos( $path, '/wp-content/debug.log' ) !== false ||
     289             ( strpos( $path, 'debug.log' ) !== false && strpos( $path, 'wp-content' ) !== false ) ) {
     290            status_header( 403 );
     291            nocache_headers();
     292            header( 'Content-Type: text/html; charset=utf-8' );
     293            die( '403 Forbidden' );
     294        }
     295    }, 1 );
     296}
     297
     298add_action( 'init', 'nhrrob_secure_protect_debug_log_init', 0 );
     299
     300/**
    138301 * Enable/Disable Features
    139302 * Example usages are shown below
     
    142305// Turn off limit login attempts
    143306// add_filter( 'nhrrob_secure_limit_login_attempts', '__return_false' );
     307
     308// Turn off custom login page
     309// add_filter( 'nhrrob_secure_custom_login_page', '__return_false' );
     310
     311// Turn off debug log protection
     312// add_filter( 'nhrrob_secure_protect_debug_log', '__return_false' );
  • nhrrob-secure/tags/1.0.3/readme.txt

    r3410319 r3434007  
    1 === NHR Secure | Protect Admin Area ===
     1=== NHR Secure | Protect Admin, Debug Logs & Limit Logins ===
    22Contributors: nhrrob
    33Tags: security, admin, login, debug, protection
     
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 1.0.2
     7Stable tag: 1.0.3
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1010
    11 A lightweight WordPress security plugin that protects your admin area by limiting login attempts.
     11A lightweight WordPress security plugin that protects your admin area, hides debug logs, and limits login attempts.
    1212
    1313== Description ==
     
    1717- Hide or protect your admin area from unauthorized access.
    1818- Limit login attempts to prevent brute-force attacks.
     19- Hide debug logs to prevent sensitive information disclosure.
    1920
    2021**Features at a glance:**
     
    5152
    52531. Failed login attempts are blocked.
     542. Custom login page.
     553. /wp-login.php or /wp-admin goes to 404.
     564. Debug log is hidden.
    5357
    5458
    5559== Changelog ==
     60
     61= 1.0.3 - 05/01/2026 =
     62- Added: Custom login page.
     63- Added: Hide debug log.
    5664
    5765= 1.0.2 - 04/12/2025 =
  • nhrrob-secure/trunk/nhrrob-secure.php

    r3410319 r3434007  
    11<?php
    22/**
    3  * Plugin Name: NHR Secure | Protect Admin Area
     3 * Plugin Name: NHR Secure | Protect Admin, Debug Logs & Limit Logins
    44 * Plugin URI: http://wordpress.org/plugins/nhrrob-secure/
    55 * Description: Lightweight WordPress security plugin that protects your admin area, hides debug logs, and limits login attempts. Minimal code, maximum protection.
    66 * Author: Nazmul Hasan Robin
    77 * Author URI: https://profiles.wordpress.org/nhrrob/
    8  * Version: 1.0.2
     8 * Version: 1.0.3
    99 * Requires at least: 6.0
    1010 * Requires PHP: 7.4
     
    1616if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    1717
    18 define( 'NHRROB_SECURE_VERSION', '1.0.2' );
     18define( 'NHRROB_SECURE_VERSION', '1.0.3' );
    1919define( 'NHRROB_SECURE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
    2020
     
    2222 * Feature List
    2323 * 1. Limit Login Attempts
    24  * 2. Protect Sensitive Files (debug.log)
     24 * 2. Custom Login Page (/hidden-access-52w instead of /wp-login.php)
     25 * 3. Protect Sensitive Files (debug.log)
    2526 */
    2627
     
    7879
    7980/**
     81 * ============================
     82 * Helper: Render 404 Page
     83 * ============================
     84 */
     85function nhrrob_secure_render_404() {
     86    wp_safe_redirect( home_url( '404' ) );
     87    exit;
     88}
     89
     90/**
    8091 * ============================================================
    8192 * 1. LIMIT LOGIN ATTEMPTS (IP + Username)
     
    136147
    137148/**
     149 * ============================================================
     150 * 2. CUSTOM LOGIN PAGE
     151 * ============================================================
     152 *
     153 * Changes default login URL from /wp-login.php to /hidden-access-52w
     154 *
     155 * Usage:
     156 * - Change the custom login URL:
     157 *   add_filter( 'nhrrob_secure_custom_login_url', fn() => '/my-custom-login' );
     158 * - Turn off the feature:
     159 *   add_filter( 'nhrrob_secure_custom_login_page', '__return_false' );
     160 */
     161function nhrrob_secure_custom_login_page_init() {
     162    if ( ! apply_filters( 'nhrrob_secure_custom_login_page', true ) ) {
     163        return;
     164    }
     165
     166    // Block direct access to wp-login.php
     167    $script_name = isset( $_SERVER['SCRIPT_NAME'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SCRIPT_NAME'] ) ) : '';
     168    if ( strpos( $script_name, '/wp-login.php' ) !== false ) {
     169        nhrrob_secure_render_404();
     170    }
     171   
     172    // Block direct access to wp-admin for guests
     173    add_action( 'init', function() {
     174        $script_name = isset( $_SERVER['SCRIPT_NAME'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SCRIPT_NAME'] ) ) : '';
     175       
     176        if ( is_admin() && ! is_user_logged_in() && ! defined( 'DOING_AJAX' ) && ! defined( 'DOING_CRON' ) ) {
     177             // Allow admin-post.php for frontend form submissions
     178             if ( strpos( $script_name, 'admin-post.php' ) === false ) {
     179                 nhrrob_secure_render_404();
     180             }
     181        }
     182    });
     183
     184    // Handle custom login URL (use template_redirect for proper WordPress context)
     185    add_action( 'template_redirect', function() {
     186        $custom_login_url = apply_filters( 'nhrrob_secure_custom_login_url', '/hidden-access-52w' );
     187        $custom_login_url = trim( $custom_login_url, '/' );
     188        $custom_login_url = '/' . ltrim( $custom_login_url, '/' );
     189
     190        $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
     191        $parsed_url = wp_parse_url( $request_uri );
     192        $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
     193
     194        // Normalize path (remove trailing slash for comparison)
     195        $path_normalized = rtrim( $path, '/' );
     196        $custom_login_url_normalized = rtrim( $custom_login_url, '/' );
     197
     198        // Check if request is for custom login URL
     199        if ( $path_normalized === $custom_login_url_normalized || $path === $custom_login_url || $path === $custom_login_url . '/' ) {
     200            // Preserve query string
     201            $query_string = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '';
     202           
     203            // Temporarily modify REQUEST_URI to load wp-login.php
     204            $_SERVER['REQUEST_URI'] = '/wp-login.php' . $query_string;
     205           
     206            // Bring globals into scope for wp-login.php
     207            global $error, $interim_login, $action, $wp_error, $user_login;
     208           
     209            // Override 404 status (since WP thinks this slug doesn't exist)
     210            if ( function_exists( 'status_header' ) ) {
     211                status_header( 200 );
     212            }
     213            if ( function_exists( 'nocache_headers' ) ) {
     214                nocache_headers();
     215            }
     216
     217
     218           
     219            // Load WordPress login
     220            require_once( ABSPATH . 'wp-login.php' );
     221           
     222
     223           
     224            exit;
     225        }
     226    }, 1 );
     227
     228    // Rewrite wp-login.php URLs to custom login URL
     229    add_filter( 'site_url', function( $url, $path, $scheme ) {
     230        if ( strpos( $url, 'wp-login.php' ) !== false ) {
     231            $custom_login_url = apply_filters( 'nhrrob_secure_custom_login_url', '/hidden-access-52w' );
     232            $custom_login_url = trim( $custom_login_url, '/' );
     233            $url = str_replace( 'wp-login.php', $custom_login_url, $url );
     234            $url = str_replace( '//' . $custom_login_url, '/' . $custom_login_url, $url ); // fix potential double slash if any
     235        }
     236        return $url;
     237    }, 10, 3 );
     238}
     239
     240add_action( 'init', 'nhrrob_secure_custom_login_page_init', 0 );
     241
     242/**
     243 * ============================================================
     244 * 3. PROTECT DEBUG LOG FILE
     245 * ============================================================
     246 *
     247 * Blocks direct access to /wp-content/debug.log
     248 * Shows 403 Forbidden for all users
     249 *
     250 * Usage:
     251 * - Turn off the feature:
     252 *   add_filter( 'nhrrob_secure_protect_debug_log', '__return_false' );
     253 */
     254function nhrrob_secure_protect_debug_log_init() {
     255    if ( ! apply_filters( 'nhrrob_secure_protect_debug_log', true ) ) {
     256        return;
     257    }
     258
     259    // Check early to catch direct file access
     260    add_action( 'plugins_loaded', function() {
     261        $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
     262        $parsed_url = wp_parse_url( $request_uri );
     263        $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
     264
     265        // Check if request is for debug.log in wp-content directory
     266        if ( strpos( $path, '/wp-content/debug.log' ) !== false ||
     267             ( strpos( $path, 'debug.log' ) !== false && strpos( $path, 'wp-content' ) !== false ) ) {
     268            if ( function_exists( 'status_header' ) ) {
     269                status_header( 403 );
     270            } else {
     271                http_response_code( 403 );
     272            }
     273            if ( function_exists( 'nocache_headers' ) ) {
     274                nocache_headers();
     275            }
     276            header( 'Content-Type: text/html; charset=utf-8' );
     277            die( '403 Forbidden' );
     278        }
     279    }, 1 );
     280
     281    // Also check in template_redirect as backup
     282    add_action( 'template_redirect', function() {
     283        $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
     284        $parsed_url = wp_parse_url( $request_uri );
     285        $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
     286
     287        // Check if request is for debug.log in wp-content directory
     288        if ( strpos( $path, '/wp-content/debug.log' ) !== false ||
     289             ( strpos( $path, 'debug.log' ) !== false && strpos( $path, 'wp-content' ) !== false ) ) {
     290            status_header( 403 );
     291            nocache_headers();
     292            header( 'Content-Type: text/html; charset=utf-8' );
     293            die( '403 Forbidden' );
     294        }
     295    }, 1 );
     296}
     297
     298add_action( 'init', 'nhrrob_secure_protect_debug_log_init', 0 );
     299
     300/**
    138301 * Enable/Disable Features
    139302 * Example usages are shown below
     
    142305// Turn off limit login attempts
    143306// add_filter( 'nhrrob_secure_limit_login_attempts', '__return_false' );
     307
     308// Turn off custom login page
     309// add_filter( 'nhrrob_secure_custom_login_page', '__return_false' );
     310
     311// Turn off debug log protection
     312// add_filter( 'nhrrob_secure_protect_debug_log', '__return_false' );
  • nhrrob-secure/trunk/readme.txt

    r3410319 r3434007  
    1 === NHR Secure | Protect Admin Area ===
     1=== NHR Secure | Protect Admin, Debug Logs & Limit Logins ===
    22Contributors: nhrrob
    33Tags: security, admin, login, debug, protection
     
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 1.0.2
     7Stable tag: 1.0.3
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1010
    11 A lightweight WordPress security plugin that protects your admin area by limiting login attempts.
     11A lightweight WordPress security plugin that protects your admin area, hides debug logs, and limits login attempts.
    1212
    1313== Description ==
     
    1717- Hide or protect your admin area from unauthorized access.
    1818- Limit login attempts to prevent brute-force attacks.
     19- Hide debug logs to prevent sensitive information disclosure.
    1920
    2021**Features at a glance:**
     
    5152
    52531. Failed login attempts are blocked.
     542. Custom login page.
     553. /wp-login.php or /wp-admin goes to 404.
     564. Debug log is hidden.
    5357
    5458
    5559== Changelog ==
     60
     61= 1.0.3 - 05/01/2026 =
     62- Added: Custom login page.
     63- Added: Hide debug log.
    5664
    5765= 1.0.2 - 04/12/2025 =
Note: See TracChangeset for help on using the changeset viewer.