PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.3.2
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.3.2
1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 1.8.0 All 210 releases
charitable / includes / users / class-charitable-roles.php

class-charitable-roles.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.3.2, at includes/users/class-charitable-roles.php

188 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Roles and Capabilities for Charitable
4 *
5 * @version 1.0.0
6 * @package Charitable/Classes/Charitable_Roles
7 * @author Eric Daams
8 * @copyright Copyright (c) 2015, Studio 164a
9 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
13
14 if ( ! class_exists( 'Charitable_Roles' ) ) :
15
16 /**
17 * Charitable_Roles class.
18 *
19 * @since 1.0.0
20 */
21 class Charitable_Roles {
22
23 /**
24 * Sets up roles for Charitable. This is called by the install script.
25 *
26 * @return void
27 * @since 1.0.0
28 */
29 public function add_roles() {
30 add_role( 'campaign_manager', __( 'Campaign Manager', 'charitable' ), array(
31 'read' => true,
32 'delete_posts' => true,
33 'edit_posts' => true,
34 'delete_published_posts' => true,
35 'publish_posts' => true,
36 'upload_files' => true,
37 'edit_published_posts' => true,
38 'read_private_pages' => true,
39 'edit_private_pages' => true,
40 'delete_private_pages' => true,
41 'read_private_posts' => true,
42 'edit_private_posts' => true,
43 'delete_private_posts' => true,
44 'delete_others_posts' => true,
45 'delete_published_pages' => true,
46 'delete_others_pages' => true,
47 'delete_pages' => true,
48 'publish_pages' => true,
49 'edit_published_pages' => true,
50 'edit_others_pages' => true,
51 'edit_pages' => true,
52 'edit_others_posts' => true,
53 'manage_links' => true,
54 'manage_categories' => true,
55 'moderate_comments' => true,
56 'import' => true,
57 'export' => true,
58 'unfiltered_html' => true
59 ) );
60
61 add_role( 'donor', __( 'Donor', 'charitable' ), array(
62 'read' => true,
63 'edit_posts' => false,
64 'delete_posts' => false
65 ) );
66 }
67
68 /**
69 * Sets up capabilities for Charitable. This is called by the install script.
70 *
71 * @global WP_Roles
72 * @return void
73 * @since 1.0.0
74 */
75 public function add_caps() {
76 global $wp_roles;
77
78 if ( class_exists('WP_Roles') ) {
79 if ( ! isset( $wp_roles ) ) {
80 $wp_roles = new WP_Roles();
81 }
82 }
83
84 if ( is_object( $wp_roles ) ) {
85
86 $wp_roles->add_cap( 'campaign_manager', 'view_charitable_sensitive_data' );
87 $wp_roles->add_cap( 'campaign_manager', 'export_charitable_reports' );
88 $wp_roles->add_cap( 'campaign_manager', 'manage_charitable_settings' );
89
90 $wp_roles->add_cap( 'administrator', 'view_charitable_sensitive_data' );
91 $wp_roles->add_cap( 'administrator', 'export_charitable_reports' );
92 $wp_roles->add_cap( 'administrator', 'manage_charitable_settings' );
93
94 // Add the main post type capabilities
95 foreach ( $this->get_core_caps() as $cap ) {
96 $wp_roles->add_cap( 'campaign_manager', $cap );
97 $wp_roles->add_cap( 'administrator', $cap );
98 }
99 }
100 }
101
102 /**
103 * Removes roles. This is called upon deactivation.
104 *
105 * @global WP_Roles
106 * @return void
107 * @access public
108 * @since 1.0.0
109 */
110 public function remove_caps() {
111 global $wp_roles;
112
113 if ( class_exists('WP_Roles') ) {
114 if ( ! isset( $wp_roles ) ) {
115 $wp_roles = new WP_Roles();
116 }
117 }
118
119 if ( is_object( $wp_roles ) ) {
120
121 $wp_roles->remove_cap( 'campaign_manager', 'view_charitable_sensitive_data' );
122 $wp_roles->remove_cap( 'campaign_manager', 'export_charitable_reports' );
123 $wp_roles->remove_cap( 'campaign_manager', 'manage_charitable_settings' );
124
125 $wp_roles->remove_cap( 'administrator', 'view_charitable_sensitive_data' );
126 $wp_roles->remove_cap( 'administrator', 'export_charitable_reports' );
127 $wp_roles->remove_cap( 'administrator', 'manage_charitable_settings' );
128
129 // Remove the main post type capabilities
130 foreach ( $this->get_core_caps() as $cap ) {
131 $wp_roles->remove_cap( 'campaign_manager', $cap );
132 $wp_roles->remove_cap( 'administrator', $cap );
133 }
134
135 remove_role( 'donor' );
136 remove_role( 'campaign_manager' );
137 }
138 }
139
140 /**
141 * Returns the caps for the post types that Charitable adds.
142 *
143 * @return array
144 * @access private
145 * @since 1.0.0
146 */
147 private function get_core_caps() {
148 return array(
149 // Campaign post type
150 'edit_campaign',
151 'read_campaign',
152 'delete_campaign',
153 'edit_campaigns',
154 'edit_others_campaigns',
155 'publish_campaigns',
156 'read_private_campaigns',
157 'delete_campaigns',
158 'delete_private_campaigns',
159 'delete_published_campaigns',
160 'delete_others_campaigns',
161 'edit_private_campaigns',
162 'edit_published_campaigns',
163
164 // Donation post type
165 'edit_donation',
166 'read_donation',
167 'delete_donation',
168 'edit_donations',
169 'edit_others_donations',
170 'publish_donations',
171 'read_private_donations',
172 'delete_donations',
173 'delete_private_donations',
174 'delete_published_donations',
175 'delete_others_donations',
176 'edit_private_donations',
177 'edit_published_donations',
178
179 // Terms
180 'manage_campaign_terms',
181 'edit_campaign_terms',
182 'delete_campaign_terms',
183 'assign_campaign_terms'
184 );
185 }
186 }
187
188 endif; // End class_exists check.