civicrm-network-groups.php 5.2 KB
Newer Older
1
2
3
<?php /*
--------------------------------------------------------------------------------
Plugin Name: CiviCRM Network Groups
Christian Wach's avatar
Christian Wach committed
4
Plugin URI: https://develop.tadpole.cc/plugins/civicrm-network-groups
5
6
Description: A plugin for the LP site to add users to a "national group".
Author: Christian Wach
Christian Wach's avatar
Christian Wach committed
7
Version: 0.2.1
8
9
10
11
12
13
14
15
16
17
Author URI: https://haystack.co.uk
Text Domain: civicrm-network-groups
Domain Path: /languages
Network: true
--------------------------------------------------------------------------------
*/



// Version.
Christian Wach's avatar
Christian Wach committed
18
define( 'CIVICRM_NETWORK_GROUPS_VERSION', '0.2.1' );
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

// Store reference to this file.
define( 'CIVICRM_NETWORK_GROUPS_FILE', __FILE__ );

// Store URL to this plugin's directory.
if ( ! defined( 'CIVICRM_NETWORK_GROUPS_URL' ) ) {
	define( 'CIVICRM_NETWORK_GROUPS_URL', plugin_dir_url( CIVICRM_NETWORK_GROUPS_FILE ) );
}

// Store PATH to this plugin's directory.
if ( ! defined( 'CIVICRM_NETWORK_GROUPS_PATH' ) ) {
	define( 'CIVICRM_NETWORK_GROUPS_PATH', plugin_dir_path( CIVICRM_NETWORK_GROUPS_FILE ) );
}



/**
 * CiviCRM Network Groups class.
 *
 * A class for encapsulating plugin functionality.
 *
 * @since 0.1
 */
class CiviCRM_Network_Groups {

44
45
46
47
48
49
50
51
52
	/**
	 * Admin object.
	 *
	 * @since 0.2
	 * @access public
	 * @var object $admin The Admin object.
	 */
	public $admin;

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
	/**
	 * WordPress object.
	 *
	 * @since 0.1
	 * @access public
	 * @var object $wordpress The WordPress object.
	 */
	public $wordpress;

	/**
	 * CiviCRM object.
	 *
	 * @since 0.1
	 * @access public
	 * @var object $civicrm The CiviCRM object.
	 */
	public $civicrm;

71
72
73
74
75
76
77
78
79
	/**
	 * Hooks object.
	 *
	 * @since 0.1
	 * @access public
	 * @var object $civicrm The Hooks object.
	 */
	public $hooks;

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
	/**
	 * Contact Layout Editor Block object.
	 *
	 * @since 0.1
	 * @access public
	 * @var object $cle The CLE Block object.
	 */
	public $cle;



	/**
	 * Initialise this object.
	 *
	 * @since 0.1
	 */
	public function __construct() {

		// Init translation.
		$this->translation();

		// Bail if CiviCRM plugin is not present.
		if ( ! function_exists( 'civi_wp' ) ) return;

		// Include files.
		$this->include_files();

		// Set up objects and references.
		$this->setup_objects();

		// Finally, register hooks.
		$this->register_hooks();

		/**
		 * Broadcast that this plugin is now loaded.
		 *
		 * @since 0.1
		 */
		do_action( 'civicrm_network_groups_loaded' );

	}



	/**
	 * Include files.
	 *
	 * @since 0.1
	 */
	public function include_files() {

131
132
133
		// Load our Admin class.
		require( CIVICRM_NETWORK_GROUPS_PATH . 'includes/civicrm-network-groups-admin.php' );

134
135
136
137
138
139
		// Load our WordPress-facing class.
		require( CIVICRM_NETWORK_GROUPS_PATH . 'includes/civicrm-network-groups-wordpress.php' );

		// Load our CiviCRM-facing class.
		require( CIVICRM_NETWORK_GROUPS_PATH . 'includes/civicrm-network-groups-civicrm.php' );

140
141
142
		// Load our Hooks class.
		require( CIVICRM_NETWORK_GROUPS_PATH . 'includes/civicrm-network-groups-hooks.php' );

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
		// Load our "Extension" Utility class.
		require( CIVICRM_NETWORK_GROUPS_PATH . 'assets/civicrm/block/civicrm-network-groups-cle-e.php' );

		// Load our CLE Block class.
		require( CIVICRM_NETWORK_GROUPS_PATH . 'assets/civicrm/block/civicrm-network-groups-cle.php' );

	}



	/**
	 * Set up this plugin's objects.
	 *
	 * @since 0.1
	 */
	public function setup_objects() {

160
161
162
		// Always instantiate Admin class.
		$this->admin = new CiviCRM_Network_Groups_Admin( $this );

163
164
165
166
167
168
		// Always instantiate WordPress class.
		$this->wordpress = new CiviCRM_Network_Groups_WordPress( $this );

		// Always instantiate CiviCRM class.
		$this->civicrm = new CiviCRM_Network_Groups_CiviCRM( $this );

169
170
171
		// Always instantiate Hooks class.
		$this->hooks = new CiviCRM_Network_Groups_Hooks( $this );

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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
		// Always instantiate CLE Block class.
		$this->cle = new CiviCRM_Network_Groups_CLE( $this );

	}



	/**
	 * Register hooks.
	 *
	 * @since 0.1
	 */
	public function register_hooks() {

		// If global-scope hooks are needed, add them here.

	}



	/**
	 * Load translation.
	 *
	 * @since 0.1
	 */
	public function translation() {

		load_plugin_textdomain(
			'civicrm-network-groups', // Unique name.
			false, // Deprecated argument.
			dirname( plugin_basename( __FILE__ ) ) . '/languages/' // Relative path.
		);

	}



	/**
	 * Check if CiviCRM is initialised.
	 *
	 * @since 0.1
	 *
	 * @return bool True if CiviCRM initialised, false otherwise.
	 */
	public function is_civicrm_initialised() {

		// Init only when CiviCRM is fully installed.
		if ( ! defined( 'CIVICRM_INSTALLED' ) ) return false;
		if ( ! CIVICRM_INSTALLED ) return false;

		// Bail if no CiviCRM init function.
		if ( ! function_exists( 'civi_wp' ) ) return false;

		// Try and initialise CiviCRM.
		return civi_wp()->initialize();

	}



} // Class ends.



/**
 * Get a reference to this plugin.
 *
 * @since 0.1
 *
 * @return CiviCRM_Network_Groups $civicrm_network_groups The plugin reference.
 */
function civicrm_network_groups() {

	// Hold the plugin instance in a static variable.
	static $civicrm_network_groups = false;

	// Instantiate plugin if not yet instantiated.
	if ( false === $civicrm_network_groups ) {
		$civicrm_network_groups = new CiviCRM_Network_Groups();
	}

	// --<
	return $civicrm_network_groups;

}

// Init plugin.
add_action( 'plugins_loaded', 'civicrm_network_groups' );