Skip to content

Commit d0895ac

Browse files
committed
🎉 Init
0 parents  commit d0895ac

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

disable-wp-frontend.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/*
3+
Plugin Name: Disable WP Frontend
4+
Plugin URI: https://github.com/fabiancdng/disable-wp-frontend
5+
Description: Disables the WordPress front end (public-facing part of the website). Leaves Dashboard, API, Media Uploads, and Cron untouched.
6+
Author: Fabian Reinders
7+
Author URI: https://fabiancdng.com
8+
Version: 1.0
9+
*/
10+
11+
// Exit if accessed directly.
12+
if ( ! defined( 'ABSPATH' ) ) {
13+
exit;
14+
}
15+
16+
if ( ! function_exists( 'disable_wp_frontend' ) ) {
17+
/**
18+
* Catch all front end requests and redirect them to wp-admin/wp-login.
19+
*/
20+
function disable_wp_frontend(): void {
21+
// Check if request is not wp-admin, wp-login.
22+
if ( ! is_admin() && ! is_login() ) {
23+
// Make sure, the request is not a media file in wp-content (like an image).
24+
// Allow all requests to wp-content/uploads/*.
25+
if ( ! str_contains( $_SERVER['REQUEST_URI'], '/wp-content/uploads/' ) ) {
26+
return;
27+
}
28+
29+
// Make sure, the request is not a call to wp-cron.php.
30+
if ( str_contains( $_SERVER['REQUEST_URI'], '/wp-cron.php' ) ) {
31+
return;
32+
}
33+
34+
// Redirect to wp-admin.
35+
wp_redirect( site_url( 'wp-admin' ) );
36+
exit;
37+
}
38+
}
39+
}
40+
41+
// Hook up to the template_redirect action (so for instance REST API calls still work).
42+
add_action( 'template_redirect', 'disable_wp_frontend' );

0 commit comments

Comments
 (0)