-
Notifications
You must be signed in to change notification settings - Fork 0
/
system-status.php
executable file
·174 lines (133 loc) · 4.3 KB
/
system-status.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/**
* System Status by imFORZA
*
* @package system-status
*/
/*
-------------------------------------------------------------------------------
Plugin Name: System Status
Plugin URI: https://www.imforza.com
Description: A WordPress plugin to manage tracking of System Incidents & Maintenance Periods.
Version: 1.0.0
Author: imFORZA
Contributors: bhubbard, sfgarza
Text Domain: system-status
Author URI: https://www.imforza.com
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
------------------------------------------------------------------------------
*/
/* Exit if accessed directly. */
if ( ! defined( 'ABSPATH' ) ) { exit; }
if ( ! class_exists( 'SystemStatus' ) ) {
/**
* TemplatePlugin class.
*
* @package system-status
**/
class SystemStatus {
/**
* Plugin Constructor.
*/
public function __construct() {
/* Define Constants */
define( 'SYSTEMSTATUS_BASE_NAME', plugin_basename( __FILE__ ) );
define( 'SYSTEMSTATUS_BASE_DIR', plugin_dir_path( __FILE__ ) );
define( 'SYSTEMSTATUS_PLUGIN_FILE', SYSTEMSTATUS_BASE_DIR . 'system-status.php' );
/* Include dependencies */
include_once( 'includes.php' );
$this->init();
}
/**
* Initialize system-status.
*/
private function init() {
/* Language Support */
load_plugin_textdomain( 'system-status', false, dirname( SYSTEMSTATUS_BASE_NAME ) . '/languages' );
/* IDX Broker Plugin Activation/De-Activation. */
register_activation_hook( SYSTEMSTATUS_PLUGIN_FILE, array( $this, 'activate' ) );
register_deactivation_hook( SYSTEMSTATUS_PLUGIN_FILE, array( $this, 'deactivate' ) );
/* Set menu page */
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
/** Enqueue css and js files */
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
/* Add link to settings in plugins admin page */
add_filter( 'plugin_action_links_' . SYSTEMSTATUS_BASE_NAME , array( $this, 'plugin_links' ) );
add_filter( 'template_include', array( $this, 'default_templates' ) );
}
/**
* Method that runs on admin_menu hook.
*/
public function admin_menu() {
}
/**
* Enqueue CSS.
*/
public function admin_scripts() {
wp_register_style( 'system-status-css', plugins_url( 'assets/css/system-status-min.css', SYSTEMSTATUS_PLUGIN_FILE ) );
wp_enqueue_style( 'system-status-css' );
}
/**
* Method that executes on plugin activation.
*/
public function activate() {
flush_rewrite_rules();
}
/**
* Method that executes on plugin de-activation.
*/
public function deactivate() {
flush_rewrite_rules();
}
/**
* Add Tools link on plugin page.
*
* @param [Array] $links : Array of links on plugin page.
* @return [Array] : Array of links on plugin page.
*/
public function plugin_links( $links ) {
$tools_link = '<a href="#">Settings</a>';
array_unshift( $links, $tools_link );
return $links;
}
public function default_templates( $template ) {
global $wp_query;
if ( is_post_type_archive( 'incident' ) ) {
if ( file_exists( get_stylesheet_directory() . '/archive-incident.php' ) ) {
$template = get_stylesheet_directory() . '/archive-incident.php';
return $template;
} else {
return SYSTEMSTATUS_BASE_DIR . '/templates/archive-incident.php';
}
}
if ( is_single() && get_post_type() === 'incident' ) {
if ( file_exists( get_stylesheet_directory() . '/single-incident.php' ) ) {
$template = get_stylesheet_directory() . '/single-incident.php';
return $template;
} else {
return SYSTEMSTATUS_BASE_DIR . '/templates/single-incident.php';
}
}
if ( is_post_type_archive( 'maintenance' ) ) {
if ( file_exists( get_stylesheet_directory() . '/archive-maintenance.php' ) ) {
$template = get_stylesheet_directory() . '/archive-maintenance.php';
return $template;
} else {
return SYSTEMSTATUS_BASE_DIR . '/templates/archive-maintenance.php';
}
}
if ( is_single() && get_post_type() === 'maintenance' ) {
if ( file_exists( get_stylesheet_directory() . '/single-maintenance.php' ) ) {
$template = get_stylesheet_directory() . '/single-maintenance.php';
return $template;
} else {
return SYSTEMSTATUS_BASE_DIR . '/templates/single-maintenance.php';
}
}
return $template;
}
}
}
/** Instantiate the plugin. */
new SystemStatus();