Skip to content

Commit

Permalink
Merge pull request #571 from publishpress/release-2.5.1
Browse files Browse the repository at this point in the history
Release 2.5.1
  • Loading branch information
olatechpro authored Sep 13, 2022
2 parents ec305a0 + cb1f52d commit 72a232a
Show file tree
Hide file tree
Showing 14 changed files with 356 additions and 199 deletions.
4 changes: 2 additions & 2 deletions capsman-enhanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: PublishPress Capabilities
* Plugin URI: https://publishpress.com/capability-manager/
* Description: Manage WordPress role definitions, per-site or network-wide. Organizes post capabilities by post type and operation.
* Version: 2.5.0
* Version: 2.5.1
* Author: PublishPress
* Author URI: https://publishpress.com/
* Text Domain: capsman-enhanced
Expand Down Expand Up @@ -44,7 +44,7 @@
}

if (!defined('CAPSMAN_VERSION')) {
define('CAPSMAN_VERSION', '2.5.0');
define('CAPSMAN_VERSION', '2.5.1');
define('CAPSMAN_ENH_VERSION', CAPSMAN_VERSION);
define('PUBLISHPRESS_CAPS_VERSION', CAPSMAN_VERSION);
}
Expand Down
60 changes: 30 additions & 30 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions includes/features/editor-features-classic.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@
continue;
}
} else {
/**
* Skip this element for post type if for some reason
* global $_wp_post_type_features is empty or doesn't
* contain data for current post type
*/
if (empty($_wp_post_type_features) || !is_array($_wp_post_type_features) || !isset($_wp_post_type_features[$type_obj->name])) {
continue;
}
//skip this element if post type does not support feature
if (!post_type_supports($type_obj->name, $arr_feature['support_key'])) {
continue;
}
Expand Down
9 changes: 9 additions & 0 deletions includes/features/editor-features-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@
continue;
}
} else {
/**
* Skip this element for post type if for some reason
* global $_wp_post_type_features is empty or doesn't
* contain data for current post type
*/
if (empty($_wp_post_type_features) || !is_array($_wp_post_type_features) || !isset($_wp_post_type_features[$type_obj->name])) {
continue;
}
//skip this element if post type does not support feature
if (!post_type_supports($type_obj->name, $arr_feature['support_key'])) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion includes/features/editor-features.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

require_once (dirname(CME_FILE) . '/includes/features/restrict-editor-features.php');

global $capsman;
global $capsman, $_wp_post_type_features;
$roles = $capsman->roles;

$default_role = $capsman->get_last_role();
Expand Down
14 changes: 8 additions & 6 deletions includes/features/restrict-editor-features.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static function elementsLayoutClassic()
$elements[esc_html__('Taxonomy Boxes', 'capsman-enhanced')] = [
'#category' => [
'label' => esc_html__('Categories', 'capsman-enhanced'),
'elements' => '#categories, #categorydiv, #categorydivsb, th.column-categories, td.categories',
'elements' => '#categories, #categorydiv, #categorydivsb, th.column-categories, td.categories, #screen-options-wrap label[for=categorydiv-hide]',
'support_key' => 'category',
'support_type' => 'taxonomy'
],
Expand All @@ -102,7 +102,7 @@ public static function elementsLayoutClassic()
],
'#post_tag' => [
'label' => esc_html__('Tags', 'capsman-enhanced'),
'elements' => '#tags, #tagsdiv,#tagsdivsb,#tagsdiv-post_tag, th.column-tags, td.tags',
'elements' => '#tags, #tagsdiv,#tagsdivsb,#tagsdiv-post_tag, th.column-tags, td.tags, #screen-options-wrap label[for=tagsdiv-post_tag-hide]',
'support_key' => 'post_tag',
'support_type' => 'taxonomy'
],
Expand All @@ -115,7 +115,7 @@ public static function elementsLayoutClassic()
if (!in_array($taxonomy, ['category', 'post_tag', 'link_category'])) {
$elements[$k]["#{$tx_obj->name}div"] = [
'label' => $tx_obj->label,
'elements' => "#{$tx_obj->name}, #{$tx_obj->name}div,#{$tx_obj->name}divsb,#tagsdiv-{$tx_obj->name}, th.column-{$tx_obj->name}, td.{$tx_obj->name}",
'elements' => "#{$tx_obj->name}, #{$tx_obj->name}div,#{$tx_obj->name}divsb,#tagsdiv-{$tx_obj->name}, th.column-{$tx_obj->name}, td.{$tx_obj->name}, #screen-options-wrap label[for=tagsdiv-{$tx_obj->name}-hide], #screen-options-wrap label[for={$tx_obj->name}div-hide]",
'support_key' => $tx_obj->name,
'support_type' => 'taxonomy'
];
Expand Down Expand Up @@ -147,16 +147,16 @@ public static function elementsLayoutClassic()
$elements[esc_html__('Other Boxes', 'capsman-enhanced')] = [
'#postimagediv' => [
'label' => esc_html__('Featured Image', 'capsman-enhanced'),
'elements' => '#postimagediv',
'elements' => '#postimagediv, #screen-options-wrap label[for=postimagediv-hide]',
'support_key' => 'thumbnail'
],
'#slug' => [
'label' => esc_html__('Post Slug', 'capsman-enhanced'),
'elements' => '#slugdiv,#edit-slug-box'
'elements' => '#slugdiv,#edit-slug-box, #screen-options-wrap label[for=slugdiv-hide]'
],
'#commentstatusdiv' => [
'label' => esc_html__('Discussion', 'capsman-enhanced'),
'elements' => '#commentstatusdiv',
'elements' => '#commentstatusdiv, #screen-options-wrap label[for=commentstatusdiv-hide]',
'support_key' => 'comments'
],
'#woocommerce-coupon-description' => [
Expand Down Expand Up @@ -212,6 +212,8 @@ public static function elementsLayoutClassic()
'elements' => '#' . $id
. ', #' . $id . 'div'
. ', th.column-' . $id
. ', #screen-options-wrap label[for='.$id.'-hide]'
. ', #screen-options-wrap label[for='.$id.'div-hide]'
. ', td.' . $id,
'support_key' => $feature
]; //th and td for raw in edit screen
Expand Down
54 changes: 54 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,60 @@ function ppc_roles_logout_redirect($redirect_to, $request, $user) {
}
add_filter('logout_redirect', 'ppc_roles_logout_redirect', 10, 3);

/**
* Block user role login
*
* @param $user (null|WP_User|WP_Error) WP_User if the user is authenticated. WP_Error or null otherwise.
*
* @return WP_User object if credentials authenticate the user. WP_Error or null otherwise
*/
function ppc_roles_wp_authenticate_user($user) {

if (is_wp_error($user)) {
return $user;
}

if (isset($user->roles) && is_array($user->roles)) {
foreach ($user->roles as $user_role) {
//get role option
$role_option = get_option("pp_capabilities_{$user_role}_role_option", []);
if (is_array($role_option) && !empty($role_option)
&& !empty($role_option['disable_role_user_login'])
&& (int)$role_option['disable_role_user_login'] > 0
) {
return new WP_Error('ppc_roles_user_banned', __('Login permission denied.', 'capsman-enhanced'));
}
}
}

return $user;
}
add_filter('wp_authenticate_user', 'ppc_roles_wp_authenticate_user', 1);

/**
* Wocommerce role admin access restriction remove
*/
function ppc_roles_disable_woocommerce_admin_restrictions($restrict_access) {

if ($restrict_access && is_user_logged_in()) {
$user = get_userdata(get_current_user_id());

if (isset($user->roles) && is_array($user->roles)) {
foreach ($user->roles as $user_role) {
//get role option
$role_option = get_option("pp_capabilities_{$user_role}_role_option", []);
if (is_array($role_option) && !empty($role_option) && !empty($role_option['disable_woocommerce_admin_restrictions'])) {
$restrict_access = false;
break;
}
}
}
}
return $restrict_access;
}
add_filter('woocommerce_prevent_admin_access', 'ppc_roles_disable_woocommerce_admin_restrictions', 20);
add_filter('woocommerce_disable_admin_bar', 'ppc_roles_disable_woocommerce_admin_restrictions', 20);

/**
* List of capabilities admin pages
*
Expand Down
8 changes: 8 additions & 0 deletions includes/roles/class/class-pp-roles-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ public function add_role()
$role_option['referer_redirect'] = !empty($_REQUEST['referer_redirect']) ? (int) $_REQUEST['referer_redirect'] : 0;
$role_option['custom_redirect'] = !empty($_REQUEST['custom_redirect']) ? (int) $_REQUEST['custom_redirect'] : 0;
$role_option['disable_code_editor'] = !empty($_REQUEST['disable_code_editor']) ? (int) $_REQUEST['disable_code_editor'] : 0;
$role_option['disable_role_user_login'] = !empty($_REQUEST['disable_role_user_login']) ? (int) $_REQUEST['disable_role_user_login'] : 0;
if (defined('WC_PLUGIN_FILE')) {
$role_option['disable_woocommerce_admin_restrictions'] = !empty($_REQUEST['disable_woocommerce_admin_restrictions']) ? (int) $_REQUEST['disable_woocommerce_admin_restrictions'] : 0;
}
update_option('pp_capabilities_' . $role['name'] . '_role_option', $role_option);

/**
Expand Down Expand Up @@ -401,6 +405,10 @@ public function edit_role()
$role_option['referer_redirect'] = !empty($_REQUEST['referer_redirect']) ? (int) $_REQUEST['referer_redirect'] : 0;
$role_option['custom_redirect'] = !empty($_REQUEST['custom_redirect']) ? (int) $_REQUEST['custom_redirect'] : 0;
$role_option['disable_code_editor'] = !empty($_REQUEST['disable_code_editor']) ? (int) $_REQUEST['disable_code_editor'] : 0;
$role_option['disable_role_user_login'] = !empty($_REQUEST['disable_role_user_login']) ? (int) $_REQUEST['disable_role_user_login'] : 0;
if (defined('WC_PLUGIN_FILE')) {
$role_option['disable_woocommerce_admin_restrictions'] = !empty($_REQUEST['disable_woocommerce_admin_restrictions']) ? (int) $_REQUEST['disable_woocommerce_admin_restrictions'] : 0;
}
update_option('pp_capabilities_' . sanitize_key($_REQUEST['current_role']) . '_role_option', $role_option);

/**
Expand Down
Loading

0 comments on commit 72a232a

Please sign in to comment.