-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc-post-types.php
331 lines (293 loc) · 8.06 KB
/
doc-post-types.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
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<?php
/*
Plugin Name: DOC Post Types
Plugin URI: https://github.com/DioceseOfCharlotte/doc-post-types
Description: DOC Content Types for WordPress.
Version: 0.7.0
Author: Marty Helmick
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: doc-posts
GitHub Plugin URI: https://github.com/DioceseOfCharlotte/doc-post-types
*/
/**
* Singleton class that sets up and initializes the plugin.
*
* @since 1.0.0
* @access public
* @return void
*/
final class Doc_Posts_Plugin {
/**
* Directory path to the plugin folder.
*
* @since 1.0.0
* @access public
* @var string
*/
public $dir_path = '';
/**
* Directory URI to the plugin folder.
*
* @since 1.0.0
* @access public
* @var string
*/
public $dir_uri = '';
/**
* Plugin CSS directory URI.
*
* @since 1.0.0
* @access public
* @var string
*/
public $css_uri = '';
/**
* Plugin JS directory URI.
*
* @since 1.0.0
* @access public
* @var string
*/
public $js_uri = '';
/**
* Plugin Image directory URI.
*
* @since 1.0.0
* @access public
* @var string
*/
public $img_uri = '';
/**
* Google maps api key.
*
* @since 1.0.0
* @access public
* @var string
*/
public $maps_api = '';
/**
* Custom post types registered.
*
* @since 1.0.0
* @access public
* @var string
*/
public $cpt_names = array(
'department',
'parish',
'school',
'aa_ministries',
'archive_post',
'bishop',
'deacon',
'development',
'development_post',
'education',
'finance',
'hispanic_ministry',
'housing',
'human_resources',
'hr_post',
'info_tech',
'liturgy',
'macs',
'multicultural',
'planning',
'property',
'schools_office',
'school_post',
'tribunal',
'vocation',
'statistics_report',
);
/**
* Returns the instance.
*
* @since 1.0.0
* @access public
* @return object
*/
public static function get_instance() {
static $instance = null;
if ( is_null( $instance ) ) {
$instance = new self;
$instance->setup();
$instance->includes();
$instance->setup_actions();
}
return $instance;
}
/**
* Constructor method.
*
* @since 1.0.0
* @access private
* @return void
*/
private function __construct() {}
/**
* Initial plugin setup.
*
* @since 1.0.0
* @access private
* @return void
*/
private function setup() {
$this->dir_path = trailingslashit( plugin_dir_path( __FILE__ ) );
$this->dir_uri = trailingslashit( plugin_dir_url( __FILE__ ) );
// Plugin assets URIs.
$this->css_uri = trailingslashit( $this->dir_uri . 'assets/styles' );
$this->js_uri = trailingslashit( $this->dir_uri . 'assets/scripts' );
$this->img_uri = trailingslashit( $this->dir_uri . 'assets/images' );
$this->maps_api = get_theme_mod( 'google_maps_api' );
}
/**
* Loads include and admin files for the plugin.
*
* @since 1.0.0
* @access private
* @return void
*/
private function includes() {
require_once $this->dir_path . 'lib/extended-cpts/extended-cpts.php';
require_once $this->dir_path . 'lib/class-gw-advanced-merge-tags.php';
require_once $this->dir_path . 'inc/customizer.php';
require_once $this->dir_path . 'inc/cpts-location.php';
require_once $this->dir_path . 'inc/post-types.php';
require_once $this->dir_path . 'inc/cpts-blog.php';
require_once $this->dir_path . 'inc/taxonomies.php';
require_once $this->dir_path . 'inc/metaboxes.php';
require_once $this->dir_path . 'inc/rest-meta.php';
require_once $this->dir_path . 'inc/parish-flow.php';
require_once $this->dir_path . 'inc/gf-parish-data.php';
require_once $this->dir_path . 'inc/documents-meta.php';
require_once $this->dir_path . 'inc/functions.php';
}
/**
* Sets up initial actions.
*
* @since 1.0.0
* @access private
* @return void
*/
private function setup_actions() {
register_activation_hook( __FILE__, array( $this, 'activation' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
}
/**
* Register scripts and styles.
*
* @since 1.0.0
* @access public
* @return void
*/
public function admin_scripts() {
wp_enqueue_media();
wp_enqueue_style( 'dpt-admin-styles', $this->css_uri . 'dpt.css' );
wp_register_script( 'bb-file', $this->js_uri . 'butterbean-media-file.js', array( 'backbone', 'wp-util', 'butterbean' ), '', true );
wp_register_script( 'geocomplete', $this->js_uri . 'address-autocomplete.js', false, false, true );
wp_register_script( 'gplaces', "https://maps.googleapis.com/maps/api/js?key={$this->maps_api}&libraries=places&callback=initAutocomplete", array( 'geocomplete' ), false, true );
}
/**
* Returns the capabilities for the post types.
*
* @since 1.0.0
* @access public
* @return array
*/
public function doc_get_capabilities( $name ) {
$caps = array(
// meta caps (don't assign these to roles)
'edit_post' => "edit_{$name}",
'read_post' => "read_{$name}",
'delete_post' => "delete_{$name}",
// primitive/meta caps
'create_posts' => "create_{$name}s",
// primitive caps used outside of map_meta_cap()
'edit_posts' => "edit_{$name}s",
'edit_others_posts' => "edit_others_{$name}s",
'publish_posts' => "publish_{$name}s",
'read_private_posts' => "read_private_{$name}s",
// primitive caps used inside of map_meta_cap()
'read' => 'read',
'delete_posts' => "delete_{$name}s",
'delete_private_posts' => "delete_private_{$name}s",
'delete_published_posts' => "delete_published_{$name}s",
'delete_others_posts' => "delete_others_{$name}s",
'edit_private_posts' => "edit_private_{$name}s",
'edit_published_posts' => "edit_published_{$name}s",
);
return apply_filters( 'doc_get_capabilities', $caps );
}
public function activation() {
$this->doc_get_capabilities( $name );
doc_register_blog_cpts();
doc_register_location_cpts();
doc_register_post_types();
doc_register_taxonomies();
$this->add_roles();
flush_rewrite_rules();
}
public function add_roles() {
foreach ( $this->cpt_names as $name ) {
add_role(
$name,
"{$name} Administrator",
array(
'read' => true,
'create_doc_documents' => true, // documents
'edit_doc_documents' => true, // documents
'manage_doc_documents' => true, // documents
'restrict_content' => true, // members
'level_1' => true, // for the author dropdown
'upload_files' => true,
"create_{$name}s" => true,
"edit_{$name}s" => true,
"edit_others_{$name}s" => true,
"publish_{$name}s" => true,
"read_private_{$name}s" => true,
"delete_{$name}s" => true,
"delete_private_{$name}s" => true,
"delete_published_{$name}s" => true,
"delete_others_{$name}s" => true,
"edit_private_{$name}s" => true,
"edit_published_{$name}s" => true,
)
);
}
// Get the administrator role.
$role = get_role( 'administrator' );
// Add required capabilities for the administrator role.
if ( ! is_null( $role ) ) {
$role->add_cap( 'create_doc_documents' );
$role->add_cap( 'edit_doc_documents' );
$role->add_cap( 'manage_doc_documents' );
foreach ( $this->cpt_names as $name ) {
// Post type caps.
$role->add_cap( "create_{$name}s" );
$role->add_cap( "edit_{$name}s" );
$role->add_cap( "edit_others_{$name}s" );
$role->add_cap( "publish_{$name}s" );
$role->add_cap( "read_private_{$name}s" );
$role->add_cap( "delete_{$name}s" );
$role->add_cap( "delete_private_{$name}s" );
$role->add_cap( "delete_published_{$name}s" );
$role->add_cap( "delete_others_{$name}s" );
$role->add_cap( "edit_private_{$name}s" );
$role->add_cap( "edit_published_{$name}s" );
}
}
}
}
/**
* Gets the instance of the main plugin class.
*
* @since 1.0.0
* @access public
* @return object
*/
function doc_posts_plugin() {
return Doc_Posts_Plugin::get_instance();
}
doc_posts_plugin();