Skip to content

Commit

Permalink
New site setup by superadmin on multisite subsite caused fatal error …
Browse files Browse the repository at this point in the history
…when saving initial settings.
  • Loading branch information
ScottDeLuzio committed Dec 9, 2019
1 parent 606cadc commit 19ab3fb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 43 deletions.
77 changes: 40 additions & 37 deletions includes/wcs-post-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,50 +35,53 @@ function wpcrm_add_role_caps() {
'contributor',
'author',
'editor',
'administrator'
'administrator',

);

$wpcrm_system_roles = apply_filters( 'wpcrm_system_default_user_roles', $roles );
foreach($post_types as $post_type) {
// Loop through each role and assign capabilities
foreach($wpcrm_system_roles as $the_role) {
$role = get_role($the_role);
// Need to check if the role has get_option('wpcrm_system_select_user_role'); capability then add_cap if it does.
if( $role->has_cap( get_option( 'wpcrm_system_select_user_role' ) ) ) {
$role->add_cap( 'edit_'.$post_type );
$role->add_cap( 'read_'.$post_type );
$role->add_cap( 'delete_'.$post_type );
$role->add_cap( 'edit_'.$post_type.'s' );
$role->add_cap( 'edit_others_'.$post_type.'s' );
$role->add_cap( 'publish_'.$post_type.'s' );
$role->add_cap( 'read_private_'.$post_type.'s' );
$role->add_cap( 'read_'.$post_type );
$role->add_cap( 'delete_'.$post_type.'s' );
$role->add_cap( 'delete_private_'.$post_type.'s' );
$role->add_cap( 'delete_published_'.$post_type.'s' );
$role->add_cap( 'delete_others_'.$post_type.'s' );
$role->add_cap( 'edit_private_'.$post_type.'s' );
$role->add_cap( 'edit_published_'.$post_type.'s' );
$role->add_cap( 'create_'.$post_type.'s' );
$role->add_cap( 'manage_wp_crm' );
} else {
// Remove the capabilities if the role isn't supposed to edit the CPT. Allows for admin to change to a higher role if too much access was previously given.
$role->remove_cap( 'edit_'.$post_type );
$role->remove_cap( 'read_'.$post_type );
$role->remove_cap( 'delete_'.$post_type );
$role->remove_cap( 'edit_'.$post_type.'s' );
$role->remove_cap( 'edit_others_'.$post_type.'s' );
$role->remove_cap( 'publish_'.$post_type.'s' );
$role->remove_cap( 'read_private_'.$post_type.'s' );
$role->remove_cap( 'read_'.$post_type );
$role->remove_cap( 'delete_'.$post_type.'s' );
$role->remove_cap( 'delete_private_'.$post_type.'s' );
$role->remove_cap( 'delete_published_'.$post_type.'s' );
$role->remove_cap( 'delete_others_'.$post_type.'s' );
$role->remove_cap( 'edit_private_'.$post_type.'s' );
$role->remove_cap( 'edit_published_'.$post_type.'s' );
$role->remove_cap( 'create_'.$post_type.'s' );
$role->remove_cap( 'manage_wp_crm' );
if( !is_null( $role ) ){
// Need to check if the role has get_option('wpcrm_system_select_user_role'); capability then add_cap if it does.
if( $role->has_cap( get_option( 'wpcrm_system_select_user_role' ) ) ) {
$role->add_cap( 'edit_'.$post_type );
$role->add_cap( 'read_'.$post_type );
$role->add_cap( 'delete_'.$post_type );
$role->add_cap( 'edit_'.$post_type.'s' );
$role->add_cap( 'edit_others_'.$post_type.'s' );
$role->add_cap( 'publish_'.$post_type.'s' );
$role->add_cap( 'read_private_'.$post_type.'s' );
$role->add_cap( 'read_'.$post_type );
$role->add_cap( 'delete_'.$post_type.'s' );
$role->add_cap( 'delete_private_'.$post_type.'s' );
$role->add_cap( 'delete_published_'.$post_type.'s' );
$role->add_cap( 'delete_others_'.$post_type.'s' );
$role->add_cap( 'edit_private_'.$post_type.'s' );
$role->add_cap( 'edit_published_'.$post_type.'s' );
$role->add_cap( 'create_'.$post_type.'s' );
$role->add_cap( 'manage_wp_crm' );
} else {
// Remove the capabilities if the role isn't supposed to edit the CPT. Allows for admin to change to a higher role if too much access was previously given.
$role->remove_cap( 'edit_'.$post_type );
$role->remove_cap( 'read_'.$post_type );
$role->remove_cap( 'delete_'.$post_type );
$role->remove_cap( 'edit_'.$post_type.'s' );
$role->remove_cap( 'edit_others_'.$post_type.'s' );
$role->remove_cap( 'publish_'.$post_type.'s' );
$role->remove_cap( 'read_private_'.$post_type.'s' );
$role->remove_cap( 'read_'.$post_type );
$role->remove_cap( 'delete_'.$post_type.'s' );
$role->remove_cap( 'delete_private_'.$post_type.'s' );
$role->remove_cap( 'delete_published_'.$post_type.'s' );
$role->remove_cap( 'delete_others_'.$post_type.'s' );
$role->remove_cap( 'edit_private_'.$post_type.'s' );
$role->remove_cap( 'edit_published_'.$post_type.'s' );
$role->remove_cap( 'create_'.$post_type.'s' );
$role->remove_cap( 'manage_wp_crm' );
}
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: scott.deluzio
Tags: WordPress CRM, Free CRM for WordPress, CRM, Free WordPress CRM, CRM for WordPress, gdpr
Requires at least: 3.3.0
Tested up to: 5.2.3
Stable tag: 3.1.2
Tested up to: 5.3.0
Stable tag: 3.1.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -91,6 +91,8 @@ Absolutely. There are inexpensive extensions that allow you to import as little
Your data is only accessible through the WordPress CRM dashboard. None of it will be accessible through the public facing portion of your website unless you are using our GDPR features (see above). This allows you to provide access to as few or as many people as you need to.

== Changelog ==
= 3.1.3 =
* Fix: New site setup by a super administrator on a multisite subsite caused fatal error when saving initial settings.
= 3.1.2 =
* Fix: Export functionality was not working due to an incorrect reference to the import/export class.
= 3.1.1 =
Expand Down Expand Up @@ -362,5 +364,5 @@ Your data is only accessible through the WordPress CRM dashboard. None of it wil
* Initial Release

== Upgrade Notice ==
= 3.1.2 =
* Fix: Export functionality was not working due to an incorrect reference to the import/export class.
= 3.1.3 =
* Fix: New site setup by a super administrator on a multisite subsite caused fatal error when saving initial settings.
4 changes: 2 additions & 2 deletions wp-crm-system.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: WP-CRM System
Plugin URI: https://www.wp-crm.com
Description: A complete CRM for WordPress
Version: 3.1.2
Version: 3.1.3
Author: Scott DeLuzio
Author URI: https://www.wp-crm.com
Text Domain: wp-crm-system
Expand Down Expand Up @@ -34,7 +34,7 @@ function wp_crm_plugin_init() {
define( 'WP_CRM_SYSTEM', __FILE__ );
}
if ( ! defined( 'WP_CRM_SYSTEM_VERSION' ) ) {
define( 'WP_CRM_SYSTEM_VERSION', '3.1.2' );
define( 'WP_CRM_SYSTEM_VERSION', '3.1.3' );
}
if( ! defined( 'WP_CRM_SYSTEM_URL' ) ) {
define( 'WP_CRM_SYSTEM_URL', plugins_url( '', __FILE__ ) );
Expand Down

0 comments on commit 19ab3fb

Please sign in to comment.