Initial commit
This commit is contained in:
47
inc/class-admin.php
Normal file
47
inc/class-admin.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* @package ogre-suspension
|
||||
* @author cleverogre
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace Ogre\Suspension;
|
||||
|
||||
use Ogre\Singleton;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
final class Admin {
|
||||
use Singleton;
|
||||
|
||||
protected function __construct() {
|
||||
add_action('init', [$this, 'logout'], 1);
|
||||
add_action('init', [$this, 'frontend_redirect'], 2);
|
||||
add_action('admin_init', [$this, 'logout'], 1);
|
||||
add_action('admin_init', [$this, 'admin_redirect'], 2);
|
||||
}
|
||||
|
||||
public function logout():void {
|
||||
if (!is_user_logged_in()) return;
|
||||
wp_logout();
|
||||
$this->do_redirect();
|
||||
}
|
||||
|
||||
public function frontend_redirect():void {
|
||||
if (is_front_page()) return;
|
||||
$this->do_redirect();
|
||||
}
|
||||
|
||||
public function admin_redirect():void {
|
||||
$this->do_redirect();
|
||||
}
|
||||
|
||||
private function do_redirect():void {
|
||||
wp_redirect(get_site_url());
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Admin::instance();
|
||||
67
inc/class-template.php
Normal file
67
inc/class-template.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* @package ogre-suspension
|
||||
* @author cleverogre
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace Ogre\Suspension;
|
||||
|
||||
use Ogre\Singleton;
|
||||
use Ogre\Suspension;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
final class Template {
|
||||
use Singleton;
|
||||
|
||||
protected function __construct() {
|
||||
add_action('template_redirect', [$this, 'template_redirect']);
|
||||
}
|
||||
|
||||
public function template_redirect():void {
|
||||
$path = self::get_path();
|
||||
if (file_exists($path)) {
|
||||
include($path);
|
||||
exit;
|
||||
} else {
|
||||
wp_die(Suspension::__('Site unavailable.'));
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_path():string {
|
||||
return Suspension::get_dir('templates/suspended.php');
|
||||
}
|
||||
|
||||
public static function get_title():string {
|
||||
return sprintf(
|
||||
'%s - %s',
|
||||
get_bloginfo('title'),
|
||||
Suspension::__('Site Unavailable')
|
||||
);
|
||||
}
|
||||
|
||||
public static function the_title():void {
|
||||
echo esc_html(self::get_title());
|
||||
}
|
||||
|
||||
public static function get_image_url():string {
|
||||
return Suspension::get_url('assets/logo.svg');
|
||||
}
|
||||
|
||||
public static function get_image():string {
|
||||
return sprintf(
|
||||
'<img src="%s" alt="%s" width="206" height="150" />',
|
||||
esc_url(self::get_image_url()),
|
||||
Suspension::esc_attr__('CleverOgre Logo')
|
||||
);
|
||||
}
|
||||
|
||||
public static function the_image():void {
|
||||
echo self::get_image();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Template::instance();
|
||||
Reference in New Issue
Block a user