diff --git a/LICENSE b/LICENSE index e62ec04..94a9ed0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ -GNU GENERAL PUBLIC LICENSE + GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found. GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . + along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. @@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see -. +. The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read -. +. diff --git a/README.md b/README.md index 9ecf776..a1854ed 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,14 @@ -# headless-wp - Plugin to enable a headless WP experience +# WP Headless +A lightweight plugin to disable the WP frontend experience. + +This enables you to use Wordpress as a backend service without any risk of security issues. + +## What the plugin actually does + +In simple terms, the plugin removes the frontend of the WordPress site. + +## Why would I want to do that? + +This is definitely not a useful plugin for a public-facing website. + +This is useful if you use Wordpress as a backend service. \ No newline at end of file diff --git a/classes/class-headless-wordpress.php b/classes/class-headless-wordpress.php new file mode 100644 index 0000000..6ef8ff7 --- /dev/null +++ b/classes/class-headless-wordpress.php @@ -0,0 +1,98 @@ +init(); + } + + /** + * Initialize class + * + * @return void + */ + public static function init() { + $ob_class = get_called_class(); + add_action( 'wp', array( $ob_class, 'headlesswp_frontend_redirect' ) ); + } + + /** + * Die if we try to access a page or the front page + * + * @return void + */ + public static function headlesswp_frontend_redirect() { + if ( ! is_admin() ) { + + /** + * Fetch the IDs of the post, page or blog page + */ + $post_ID = get_the_id(); + $homepage_id = get_option( 'page_on_front' ); + $blogpage_id = get_option( 'page_for_posts' ); + + /** + * Do a wp_die so we can't access the site + */ + if ( $homepage_id === $post_ID || $blogpage_id === $post_ID || is_front_page() ) { + wp_die( 'This site is not accessible' ); + exit; + } else { + + /** + * Else do a redirect back to WP admin again + */ + + $post_edit_link = admin_url( 'post.php?post=' . $post_ID . '&action=edit' ); + + if ( is_user_logged_in() ) { + /** + * Logged in users go to the post edit screen + */ + wp_safe_redirect( $post_edit_link ); + exit; + } else { + /** + * Not logged in? Redirect to login page + */ + wp_safe_redirect( wp_login_url( $post_edit_link ) ); + exit; + } + } + } + } + + /** + * Get class object instance + * + * @return object + */ + public static function get_instance() { + if ( ! self::$instance ) { + self::$instance = new Headless_WordPress(); + } + return self::$instance; + } +} diff --git a/headless-wordpress.php b/headless-wordpress.php new file mode 100644 index 0000000..d432ada --- /dev/null +++ b/headless-wordpress.php @@ -0,0 +1,40 @@ +