| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | * Roles and Capabilities |
| 4 | 4 | * |
| 5 | 5 | * @package Give |
| 6 | 6 | * @subpackage Classes/Give_Roles |
| 7 | - * @copyright Copyright (c) 2016, WordImpress | |
| 7 | + * @copyright Copyright (c) 2016, GiveWP | |
| 8 | 8 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 9 | 9 | * @since 1.0 |
| 10 | 10 | */ |
| 11 | 11 | |
| @@ -50,56 +50,72 @@ | ||
| 50 | 50 | * |
| 51 | 51 | * @return void |
| 52 | 52 | */ |
| 53 | 53 | public function add_roles() { |
| 54 | - add_role( 'give_manager', __( 'Give Manager', 'give' ), array( | |
| 55 | - 'read' => true, | |
| 56 | - 'edit_posts' => true, | |
| 57 | - 'delete_posts' => true, | |
| 58 | - 'unfiltered_html' => true, | |
| 59 | - 'upload_files' => true, | |
| 60 | - 'export' => false, | |
| 61 | - 'import' => false, | |
| 62 | - 'delete_others_pages' => false, | |
| 63 | - 'delete_others_posts' => false, | |
| 64 | - 'delete_pages' => true, | |
| 65 | - 'delete_private_pages' => true, | |
| 66 | - 'delete_private_posts' => true, | |
| 67 | - 'delete_published_pages' => true, | |
| 68 | - 'delete_published_posts' => true, | |
| 69 | - 'edit_others_pages' => false, | |
| 70 | - 'edit_others_posts' => false, | |
| 71 | - 'edit_pages' => true, | |
| 72 | - 'edit_private_pages' => true, | |
| 73 | - 'edit_private_posts' => true, | |
| 74 | - 'edit_published_pages' => true, | |
| 75 | - 'edit_published_posts' => true, | |
| 76 | - 'manage_categories' => false, | |
| 77 | - 'manage_links' => true, | |
| 78 | - 'moderate_comments' => true, | |
| 79 | - 'publish_pages' => true, | |
| 80 | - 'publish_posts' => true, | |
| 81 | - 'read_private_pages' => true, | |
| 82 | - 'read_private_posts' => true, | |
| 83 | - ) ); | |
| 54 | + add_role( | |
| 55 | + 'give_manager', | |
| 56 | + __( 'GiveWP Manager', 'give' ), | |
| 57 | + array( | |
| 58 | + 'read' => true, | |
| 59 | + 'edit_posts' => true, | |
| 60 | + 'delete_posts' => true, | |
| 61 | + 'unfiltered_html' => true, | |
| 62 | + 'upload_files' => true, | |
| 63 | + 'export' => false, | |
| 64 | + 'import' => false, | |
| 65 | + 'delete_others_pages' => false, | |
| 66 | + 'delete_others_posts' => false, | |
| 67 | + 'delete_pages' => true, | |
| 68 | + 'delete_private_pages' => true, | |
| 69 | + 'delete_private_posts' => true, | |
| 70 | + 'delete_published_pages' => true, | |
| 71 | + 'delete_published_posts' => true, | |
| 72 | + 'edit_others_pages' => false, | |
| 73 | + 'edit_others_posts' => false, | |
| 74 | + 'edit_pages' => true, | |
| 75 | + 'edit_private_pages' => true, | |
| 76 | + 'edit_private_posts' => true, | |
| 77 | + 'edit_published_pages' => true, | |
| 78 | + 'edit_published_posts' => true, | |
| 79 | + 'manage_categories' => false, | |
| 80 | + 'manage_links' => true, | |
| 81 | + 'moderate_comments' => true, | |
| 82 | + 'publish_pages' => true, | |
| 83 | + 'publish_posts' => true, | |
| 84 | + 'read_private_pages' => true, | |
| 85 | + 'read_private_posts' => true, | |
| 86 | + ) | |
| 87 | + ); | |
| 84 | 88 | |
| 85 | - add_role( 'give_accountant', __( 'Give Accountant', 'give' ), array( | |
| 86 | - 'read' => true, | |
| 87 | - 'edit_posts' => false, | |
| 88 | - 'delete_posts' => false, | |
| 89 | - ) ); | |
| 89 | + add_role( | |
| 90 | + 'give_accountant', | |
| 91 | + __( 'GiveWP Accountant', 'give' ), | |
| 92 | + array( | |
| 93 | + 'read' => true, | |
| 94 | + 'edit_posts' => false, | |
| 95 | + 'delete_posts' => false, | |
| 96 | + ) | |
| 97 | + ); | |
| 90 | 98 | |
| 91 | - add_role( 'give_worker', __( 'Give Worker', 'give' ), array( | |
| 92 | - 'read' => true, | |
| 93 | - 'edit_posts' => true, | |
| 94 | - 'edit_pages' => true, | |
| 95 | - 'upload_files' => true, | |
| 96 | - 'delete_posts' => false, | |
| 97 | - ) ); | |
| 99 | + add_role( | |
| 100 | + 'give_worker', | |
| 101 | + __( 'GiveWP Worker', 'give' ), | |
| 102 | + array( | |
| 103 | + 'read' => true, | |
| 104 | + 'edit_posts' => true, | |
| 105 | + 'edit_pages' => true, | |
| 106 | + 'upload_files' => true, | |
| 107 | + 'delete_posts' => false, | |
| 108 | + ) | |
| 109 | + ); | |
| 98 | 110 | |
| 99 | - add_role( 'give_donor', __( 'Give Donor', 'give' ), array( | |
| 100 | - 'read' => true, | |
| 101 | - ) ); | |
| 111 | + add_role( | |
| 112 | + 'give_donor', | |
| 113 | + __( 'GiveWP Donor', 'give' ), | |
| 114 | + array( | |
| 115 | + 'read' => true, | |
| 116 | + ) | |
| 117 | + ); | |
| 102 | 118 | |
| 103 | 119 | } |
| 104 | 120 | |
| 105 | 121 | /** |
| @@ -145,9 +161,11 @@ | ||
| 145 | 161 | } |
| 146 | 162 | } |
| 147 | 163 | |
| 148 | 164 | // Add Capabilities to Give Workers User Role. |
| 149 | - $wp_roles->add_cap( 'give_worker', 'edit_give_payments' ); | |
| 165 | + // @since 4.14.0 replaced edit_give_payments with view_give_payments, added view_give_forms | |
| 166 | + $wp_roles->add_cap( 'give_worker', 'view_give_payments' ); | |
| 167 | + $wp_roles->add_cap( 'give_worker', 'view_give_forms' ); | |
| 150 | 168 | $wp_roles->add_cap( 'give_worker', 'delete_give_forms' ); |
| 151 | 169 | $wp_roles->add_cap( 'give_worker', 'delete_others_give_forms' ); |
| 152 | 170 | $wp_roles->add_cap( 'give_worker', 'delete_private_give_forms' ); |
| 153 | 171 | $wp_roles->add_cap( 'give_worker', 'delete_published_give_forms' ); |
| @@ -158,9 +176,10 @@ | ||
| 158 | 176 | $wp_roles->add_cap( 'give_worker', 'publish_give_forms' ); |
| 159 | 177 | $wp_roles->add_cap( 'give_worker', 'read_private_give_forms' ); |
| 160 | 178 | |
| 161 | 179 | // Add Capabilities to Give Accountant User Role. |
| 162 | - $wp_roles->add_cap( 'give_accountant', 'edit_give_forms' ); | |
| 180 | + // @since 4.14.0 replaced edit_give_forms with view_give_forms | |
| 181 | + $wp_roles->add_cap( 'give_accountant', 'view_give_forms' ); | |
| 163 | 182 | $wp_roles->add_cap( 'give_accountant', 'read_private_give_forms' ); |
| 164 | 183 | $wp_roles->add_cap( 'give_accountant', 'view_give_reports' ); |
| 165 | 184 | $wp_roles->add_cap( 'give_accountant', 'export_give_reports' ); |
| 166 | 185 | $wp_roles->add_cap( 'give_accountant', 'edit_give_payments' ); |
| @@ -173,8 +192,9 @@ | ||
| 173 | 192 | * Get Core Capabilities |
| 174 | 193 | * |
| 175 | 194 | * Retrieve core post type capabilities. |
| 176 | 195 | * |
| 196 | + * @since 4.14.0 added view to capability types | |
| 177 | 197 | * @since 1.0 |
| 178 | 198 | * @access public |
| 179 | 199 | * |
| 180 | 200 | * @return array $capabilities Core post type capabilities. |
| @@ -186,11 +206,9 @@ | ||
| 186 | 206 | |
| 187 | 207 | foreach ( $capability_types as $capability_type ) { |
| 188 | 208 | $capabilities[ $capability_type ] = array( |
| 189 | 209 | // Post type. |
| 190 | - "edit_{$capability_type}", | |
| 191 | - "read_{$capability_type}", | |
| 192 | - "delete_{$capability_type}", | |
| 210 | + "view_{$capability_type}s", | |
| 193 | 211 | "edit_{$capability_type}s", |
| 194 | 212 | "edit_others_{$capability_type}s", |
| 195 | 213 | "publish_{$capability_type}s", |
| 196 | 214 | "read_private_{$capability_type}s", |
| @@ -234,10 +252,9 @@ | ||
| 234 | 252 | public function meta_caps( $caps, $cap, $user_id, $args ) { |
| 235 | 253 | |
| 236 | 254 | switch ( $cap ) { |
| 237 | 255 | |
| 238 | - case 'view_give_form_stats' : | |
| 239 | - | |
| 256 | + case 'view_give_form_stats': | |
| 240 | 257 | if ( empty( $args[0] ) ) { |
| 241 | 258 | break; |
| 242 | 259 | } |
| 243 | 260 | |
| @@ -261,8 +278,9 @@ | ||
| 261 | 278 | * Remove Capabilities |
| 262 | 279 | * |
| 263 | 280 | * Remove core post type capabilities (called on uninstall). |
| 264 | 281 | * |
| 282 | + * @since 4.14.0 added view_give_payments to remove list | |
| 265 | 283 | * @since 1.0 |
| 266 | 284 | * @access public |
| 267 | 285 | * |
| 268 | 286 | * @global WP_Roles $wp_roles |
| @@ -284,8 +302,9 @@ | ||
| 284 | 302 | $wp_roles->remove_cap( 'give_manager', 'view_give_reports' ); |
| 285 | 303 | $wp_roles->remove_cap( 'give_manager', 'view_give_sensitive_data' ); |
| 286 | 304 | $wp_roles->remove_cap( 'give_manager', 'export_give_reports' ); |
| 287 | 305 | $wp_roles->remove_cap( 'give_manager', 'manage_give_settings' ); |
| 306 | + $wp_roles->remove_cap( 'give_manager', 'view_give_payments' ); | |
| 288 | 307 | |
| 289 | 308 | // Site Administrator Capabilities. |
| 290 | 309 | $wp_roles->remove_cap( 'administrator', 'view_give_reports' ); |
| 291 | 310 | $wp_roles->remove_cap( 'administrator', 'view_give_sensitive_data' ); |
| @@ -304,9 +323,10 @@ | ||
| 304 | 323 | } |
| 305 | 324 | } |
| 306 | 325 | |
| 307 | 326 | // Remove capabilities from the Give Worker role. |
| 308 | - $wp_roles->remove_cap( 'give_worker', 'edit_give_payments' ); | |
| 327 | + $wp_roles->remove_cap( 'give_worker', 'view_give_payments' ); | |
| 328 | + $wp_roles->remove_cap( 'give_worker', 'view_give_forms' ); | |
| 309 | 329 | $wp_roles->remove_cap( 'give_worker', 'delete_give_forms' ); |
| 310 | 330 | $wp_roles->remove_cap( 'give_worker', 'delete_others_give_forms' ); |
| 311 | 331 | $wp_roles->remove_cap( 'give_worker', 'delete_private_give_forms' ); |
| 312 | 332 | $wp_roles->remove_cap( 'give_worker', 'delete_published_give_forms' ); |
| @@ -317,9 +337,10 @@ | ||
| 317 | 337 | $wp_roles->remove_cap( 'give_worker', 'publish_give_forms' ); |
| 318 | 338 | $wp_roles->remove_cap( 'give_worker', 'read_private_give_forms' ); |
| 319 | 339 | |
| 320 | 340 | // Remove Capabilities from Give Accountant User Role. |
| 321 | - $wp_roles->remove_cap( 'give_accountant', 'edit_give_forms' ); | |
| 341 | + // @since 4.14.0 replaced edit_give_forms with view_give_forms | |
| 342 | + $wp_roles->remove_cap( 'give_accountant', 'view_give_forms' ); | |
| 322 | 343 | $wp_roles->remove_cap( 'give_accountant', 'read_private_give_forms' ); |
| 323 | 344 | $wp_roles->remove_cap( 'give_accountant', 'view_give_reports' ); |
| 324 | 345 | $wp_roles->remove_cap( 'give_accountant', 'export_give_reports' ); |
| 325 | 346 | $wp_roles->remove_cap( 'give_accountant', 'edit_give_payments' ); |
| @@ -333,15 +354,15 @@ | ||
| 333 | 354 | * |
| 334 | 355 | * Note: WooCommerce doesn't allow the user to access the WP dashboard who holds "Give Accountant" role. |
| 335 | 356 | * |
| 336 | 357 | * @since 1.8.14 |
| 337 | - * @updated 1.8.18 - Fixed Give conflicting by not returning $show_admin_bar https://github.com/WordImpress/Give/issues/2539 | |
| 358 | + * @updated 1.8.18 - Fixed Give conflicting by not returning $show_admin_bar https://github.com/impress-org/give/issues/2539 | |
| 338 | 359 | * |
| 339 | 360 | * @param bool |
| 340 | 361 | * |
| 341 | 362 | * @return bool |
| 342 | 363 | */ |
| 343 | - public function manage_admin_dashboard($show_admin_bar) { | |
| 364 | + public function manage_admin_dashboard( $show_admin_bar ) { | |
| 344 | 365 | |
| 345 | 366 | // Get the current logged user. |
| 346 | 367 | $current_user = wp_get_current_user(); |
| 347 | 368 | |