-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcgc-group-accounts.php
181 lines (149 loc) · 4.19 KB
/
cgc-group-accounts.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
<?php
/*
Plugin Name: CG Cookie - Group Accounts
Plugin URL: https://github.com/CGCookie/cgc-group-accounts
Description: Provides the database and API for group accounts on the CG Cookie education network
Version: 1.4
Author: Pippin Williamson
Author URI: http://cgcookie.com
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'CGC_Group_Accounts' ) ) :
/**
* Main CGC_Group_Accounts Class
*
* @since 1.0
*/
final class CGC_Group_Accounts {
/** Singleton ************************************************************/
/**
* @var CGC_Group_Accounts The one true CGC_Group_Accounts
* @since 1.0
*/
private static $instance;
/**
* The version number of CGC Groups
*
* @since 1.0
*/
private $version = '1.4';
/**
* The groups DB instance variable.
*
* @var CGC_Groups
* @since 1.0
*/
public $groups;
/**
* The members instance variable.
*
* @var CGC_Group_Members
* @since 1.0
*/
public $members;
/**
* The capabilities instance variable.
*
* @var CGC_Group_Capabilities
* @since 1.0
*/
public $capabilities;
/**
* Main CGC_Group_Accounts Instance
*
* Insures that only one instance of CGC_Group_Accounts exists in memory at any one
* time. Also prevents needing to define globals all over the place.
*
* @since 1.0
* @static var array $instance
* @uses CGC_Group_Accounts::includes() Include the required files
* @uses CGC_Group_Accounts::setup_actions() Setup the hooks and actions
* @return CGC_Group_Accounts
*/
public static function instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof CGC_Group_Accounts ) ) {
self::$instance = new CGC_Group_Accounts;
self::$instance->constants();
self::$instance->includes();
// Setup objects
self::$instance->groups = new CGC_Groups;
self::$instance->members = new CGC_Group_Members;
self::$instance->capabilities = new CGC_Group_Capabilities;
}
return self::$instance;
}
/**
* Setup plugin constants
*
* @access private
* @since 1.0
* @return void
*/
private function constants() {
// Plugin version
if ( ! defined( 'CGC_GROUPS_VERSION' ) ) {
define( 'CGC_GROUPS_VERSION', $this->version );
}
// Plugin Folder Path
if ( ! defined( 'CGC_GROUPS_PLUGIN_DIR' ) ) {
define( 'CGC_GROUPS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
// Plugin Folder URL
if ( ! defined( 'CGC_GROUPS_PLUGIN_URL' ) ) {
define( 'CGC_GROUPS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
// Plugin Root File
if ( ! defined( 'CGC_GROUPS_PLUGIN_FILE' ) ) {
define( 'CGC_GROUPS_PLUGIN_FILE', __FILE__ );
}
}
/**
* Include required files
*
* @access private
* @since 1.0
* @return void
*/
private function includes() {
require_once CGC_GROUPS_PLUGIN_DIR . 'includes/class-capabilities.php';
require_once CGC_GROUPS_PLUGIN_DIR . 'includes/class-db-base.php';
require_once CGC_GROUPS_PLUGIN_DIR . 'includes/class-db-groups.php';
require_once CGC_GROUPS_PLUGIN_DIR . 'includes/class-db-group-members.php';
require_once CGC_GROUPS_PLUGIN_DIR . 'includes/class-actions.php';
if( is_admin() ) {
require_once CGC_GROUPS_PLUGIN_DIR . 'includes/admin/class-menu.php';
require_once CGC_GROUPS_PLUGIN_DIR . 'includes/admin/class-notices.php';
} else {
require_once CGC_GROUPS_PLUGIN_DIR . 'includes/class-shortcodes.php';
require_once CGC_GROUPS_PLUGIN_DIR . 'includes/frontend/class-notices.php';
}
}
}
endif; // End if class_exists check
/**
* The main function responsible for returning the one true CGC_Group_Accounts
* Instance to functions everywhere.
*
* Use this function like you would a global variable, except without needing
* to declare the global.
*
* Example: <?php $CGC_Group_Accounts = CGC_Group_Accounts(); ?>
*
* @since 1.0
* @return object The one true CGC_Group_Accounts Instance
*/
function cgc_group_accounts() {
return CGC_Group_Accounts::instance();
}
cgc_group_accounts();
/**
* Create database tables during install
*
* @since 1.0
*/
function cgc_group_accounts_install() {
cgc_group_accounts()->groups->create_table();
cgc_group_accounts()->members->create_table();
}
register_activation_hook( __FILE__, 'cgc_group_accounts_install' );