Changeset 3434007
- Timestamp:
- 01/07/2026 02:02:45 AM (3 months ago)
- Location:
- nhrrob-secure
- Files:
-
- 3 added
- 4 edited
- 1 copied
-
assets/screenshot-2.png (added)
-
assets/screenshot-3.png (added)
-
assets/screenshot-4.png (added)
-
tags/1.0.3 (copied) (copied from nhrrob-secure/trunk)
-
tags/1.0.3/nhrrob-secure.php (modified) (6 diffs)
-
tags/1.0.3/readme.txt (modified) (4 diffs)
-
trunk/nhrrob-secure.php (modified) (6 diffs)
-
trunk/readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
nhrrob-secure/tags/1.0.3/nhrrob-secure.php
r3410319 r3434007 1 1 <?php 2 2 /** 3 * Plugin Name: NHR Secure | Protect Admin Area3 * Plugin Name: NHR Secure | Protect Admin, Debug Logs & Limit Logins 4 4 * Plugin URI: http://wordpress.org/plugins/nhrrob-secure/ 5 5 * Description: Lightweight WordPress security plugin that protects your admin area, hides debug logs, and limits login attempts. Minimal code, maximum protection. 6 6 * Author: Nazmul Hasan Robin 7 7 * Author URI: https://profiles.wordpress.org/nhrrob/ 8 * Version: 1.0. 28 * Version: 1.0.3 9 9 * Requires at least: 6.0 10 10 * Requires PHP: 7.4 … … 16 16 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly 17 17 18 define( 'NHRROB_SECURE_VERSION', '1.0. 2' );18 define( 'NHRROB_SECURE_VERSION', '1.0.3' ); 19 19 define( 'NHRROB_SECURE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 20 20 … … 22 22 * Feature List 23 23 * 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) 25 26 */ 26 27 … … 78 79 79 80 /** 81 * ============================ 82 * Helper: Render 404 Page 83 * ============================ 84 */ 85 function nhrrob_secure_render_404() { 86 wp_safe_redirect( home_url( '404' ) ); 87 exit; 88 } 89 90 /** 80 91 * ============================================================ 81 92 * 1. LIMIT LOGIN ATTEMPTS (IP + Username) … … 136 147 137 148 /** 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 */ 161 function 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 240 add_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 */ 254 function 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 298 add_action( 'init', 'nhrrob_secure_protect_debug_log_init', 0 ); 299 300 /** 138 301 * Enable/Disable Features 139 302 * Example usages are shown below … … 142 305 // Turn off limit login attempts 143 306 // 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 === 2 2 Contributors: nhrrob 3 3 Tags: security, admin, login, debug, protection … … 5 5 Tested up to: 6.9 6 6 Requires PHP: 7.4 7 Stable tag: 1.0. 27 Stable tag: 1.0.3 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 A lightweight WordPress security plugin that protects your admin area by limitinglogin attempts.11 A lightweight WordPress security plugin that protects your admin area, hides debug logs, and limits login attempts. 12 12 13 13 == Description == … … 17 17 - Hide or protect your admin area from unauthorized access. 18 18 - Limit login attempts to prevent brute-force attacks. 19 - Hide debug logs to prevent sensitive information disclosure. 19 20 20 21 **Features at a glance:** … … 51 52 52 53 1. Failed login attempts are blocked. 54 2. Custom login page. 55 3. /wp-login.php or /wp-admin goes to 404. 56 4. Debug log is hidden. 53 57 54 58 55 59 == Changelog == 60 61 = 1.0.3 - 05/01/2026 = 62 - Added: Custom login page. 63 - Added: Hide debug log. 56 64 57 65 = 1.0.2 - 04/12/2025 = -
nhrrob-secure/trunk/nhrrob-secure.php
r3410319 r3434007 1 1 <?php 2 2 /** 3 * Plugin Name: NHR Secure | Protect Admin Area3 * Plugin Name: NHR Secure | Protect Admin, Debug Logs & Limit Logins 4 4 * Plugin URI: http://wordpress.org/plugins/nhrrob-secure/ 5 5 * Description: Lightweight WordPress security plugin that protects your admin area, hides debug logs, and limits login attempts. Minimal code, maximum protection. 6 6 * Author: Nazmul Hasan Robin 7 7 * Author URI: https://profiles.wordpress.org/nhrrob/ 8 * Version: 1.0. 28 * Version: 1.0.3 9 9 * Requires at least: 6.0 10 10 * Requires PHP: 7.4 … … 16 16 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly 17 17 18 define( 'NHRROB_SECURE_VERSION', '1.0. 2' );18 define( 'NHRROB_SECURE_VERSION', '1.0.3' ); 19 19 define( 'NHRROB_SECURE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 20 20 … … 22 22 * Feature List 23 23 * 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) 25 26 */ 26 27 … … 78 79 79 80 /** 81 * ============================ 82 * Helper: Render 404 Page 83 * ============================ 84 */ 85 function nhrrob_secure_render_404() { 86 wp_safe_redirect( home_url( '404' ) ); 87 exit; 88 } 89 90 /** 80 91 * ============================================================ 81 92 * 1. LIMIT LOGIN ATTEMPTS (IP + Username) … … 136 147 137 148 /** 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 */ 161 function 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 240 add_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 */ 254 function 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 298 add_action( 'init', 'nhrrob_secure_protect_debug_log_init', 0 ); 299 300 /** 138 301 * Enable/Disable Features 139 302 * Example usages are shown below … … 142 305 // Turn off limit login attempts 143 306 // 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 === 2 2 Contributors: nhrrob 3 3 Tags: security, admin, login, debug, protection … … 5 5 Tested up to: 6.9 6 6 Requires PHP: 7.4 7 Stable tag: 1.0. 27 Stable tag: 1.0.3 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 A lightweight WordPress security plugin that protects your admin area by limitinglogin attempts.11 A lightweight WordPress security plugin that protects your admin area, hides debug logs, and limits login attempts. 12 12 13 13 == Description == … … 17 17 - Hide or protect your admin area from unauthorized access. 18 18 - Limit login attempts to prevent brute-force attacks. 19 - Hide debug logs to prevent sensitive information disclosure. 19 20 20 21 **Features at a glance:** … … 51 52 52 53 1. Failed login attempts are blocked. 54 2. Custom login page. 55 3. /wp-login.php or /wp-admin goes to 404. 56 4. Debug log is hidden. 53 57 54 58 55 59 == Changelog == 60 61 = 1.0.3 - 05/01/2026 = 62 - Added: Custom login page. 63 - Added: Hide debug log. 56 64 57 65 = 1.0.2 - 04/12/2025 =
Note: See TracChangeset
for help on using the changeset viewer.