-
Notifications
You must be signed in to change notification settings - Fork 0
/
sof-resources.php
197 lines (156 loc) · 3.7 KB
/
sof-resources.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
/**
* SOF Resources
*
* Plugin Name: SOF Resources
* Description: Provides Resources and associated functionality.
* Plugin URI: https://github.com/spiritoffootball/sof-resources
* Version: 1.0.0
* Author: Christian Wach
* Author URI: https://haystack.co.uk
* Text Domain: sof-resources
* Domain Path: /languages
*
* @package Spirit_Of_Football_Resources
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
// Set our version here.
define( 'SOF_RESOURCES_VERSION', '1.0.0' );
// Store reference to this file.
if ( ! defined( 'SOF_RESOURCES_FILE' ) ) {
define( 'SOF_RESOURCES_FILE', __FILE__ );
}
// Store URL to this plugin's directory.
if ( ! defined( 'SOF_RESOURCES_URL' ) ) {
define( 'SOF_RESOURCES_URL', plugin_dir_url( SOF_RESOURCES_FILE ) );
}
// Store PATH to this plugin's directory.
if ( ! defined( 'SOF_RESOURCES_PATH' ) ) {
define( 'SOF_RESOURCES_PATH', plugin_dir_path( SOF_RESOURCES_FILE ) );
}
/**
* SOF Resources Class.
*
* A class that encapsulates network-wide quotations.
*
* @since 0.1
*/
class Spirit_Of_Football_Resources {
/**
* Custom Post Type object.
*
* @since 0.1
* @access public
* @var Spirit_Of_Football_Resources_CPT
*/
public $cpt;
/**
* Metaboxes object.
*
* @since 0.1
* @access public
* @var Spirit_Of_Football_Resources_Metaboxes
*/
public $metaboxes;
/**
* Constructor.
*
* @since 0.1
*/
public function __construct() {
// Include files.
$this->include_files();
// Setup globals.
$this->setup_globals();
// Register hooks.
$this->register_hooks();
}
/**
* Include files.
*
* @since 0.1
*/
public function include_files() {
// Include class files.
include_once SOF_RESOURCES_PATH . 'includes/sof-resources-cpt.php';
include_once SOF_RESOURCES_PATH . 'includes/sof-resources-metaboxes.php';
}
/**
* Set up objects.
*
* @since 0.1
*/
public function setup_globals() {
// Instantiate objects.
$this->cpt = new Spirit_Of_Football_Resources_CPT();
$this->metaboxes = new Spirit_Of_Football_Resources_Metaboxes();
}
/**
* Register WordPress hooks.
*
* @since 0.1
*/
public function register_hooks() {
// Use translation.
add_action( 'plugins_loaded', [ $this, 'translation' ] );
// Hooks that always need to be present.
$this->cpt->register_hooks();
$this->metaboxes->register_hooks();
}
/**
* Actions to perform on plugin activation.
*
* @since 0.1
*/
public function activate() {
// Pass through.
$this->cpt->activate();
}
/**
* Actions to perform on plugin deactivation NOT deletion.
*
* @since 0.1
*/
public function deactivate() {
// Pass through.
$this->cpt->deactivate();
}
/**
* Loads translation.
*
* @since 0.1
*/
public function translation() {
// Load translations.
// phpcs:ignore WordPress.WP.DeprecatedParameters.Load_plugin_textdomainParam2Found
load_plugin_textdomain(
'sof-resources', // Unique name.
false, // Deprecated argument.
dirname( plugin_basename( SOF_RESOURCES_FILE ) ) . '/languages/' // Relative path to files.
);
}
}
/**
* Utility to get a reference to this plugin.
*
* @since 0.1
*
* @return Spirit_Of_Football_Resources $plugin The plugin reference.
*/
function spirit_of_football_resources() {
// Store instance in static variable.
static $plugin = false;
// Maybe return instance.
if ( false === $plugin ) {
$plugin = new Spirit_Of_Football_Resources();
}
// --<
return $plugin;
}
// Initialise plugin now.
spirit_of_football_resources();
// Activation.
register_activation_hook( __FILE__, [ spirit_of_football_resources(), 'activate' ] );
// Deactivation.
register_deactivation_hook( __FILE__, [ spirit_of_football_resources(), 'deactivate' ] );