PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.6.31
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.6.31
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.6.31, at includes/users/class-charitable-roles.php

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