Skip to content

Commit

Permalink
Merge pull request #1184 from publishpress/release-v2.14.0
Browse files Browse the repository at this point in the history
Release v2.14.0
  • Loading branch information
olatechpro authored Oct 22, 2024
2 parents c613607 + dfc9419 commit 10696be
Show file tree
Hide file tree
Showing 27 changed files with 6,426 additions and 6,034 deletions.
11 changes: 9 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.13.0
* Version: 2.14.0
* Author: PublishPress
* Author URI: https://publishpress.com/
* Text Domain: capability-manager-enhanced
Expand Down Expand Up @@ -69,7 +69,7 @@
add_action('plugins_loaded', function () {

if (!defined('CAPSMAN_VERSION')) {
define('CAPSMAN_VERSION', '2.13.0');
define('CAPSMAN_VERSION', '2.14.0');
define('CAPSMAN_ENH_VERSION', CAPSMAN_VERSION);
define('PUBLISHPRESS_CAPS_VERSION', CAPSMAN_VERSION);
}
Expand Down Expand Up @@ -173,3 +173,10 @@ function ($links, $file) {
}
do_action('publishpress_capabilities_loaded');
}, -10);

register_activation_hook(
__FILE__,
function () {
update_option('pp_capabilities_activated', true);
}
);
16 changes: 8 additions & 8 deletions common/js/admin.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jQuery(document).ready( function($) {
//$('table.cme-typecaps span.cap-x,table.cme-checklist span.cap-x,table.cme-checklist td.cap-neg span').live( 'click', function(e) {
$(document).on( 'click', 'table.cme-typecaps span.cap-x,table.cme-checklist span.cap-x,table.cme-checklist td.cap-neg span', function(e) {
$(this).closest('td').removeClass('cap-neg').removeClass('cap-yes').addClass('cap-no');
$(this).parent().find('input[type="checkbox"]').prop('checked',false);
$(this).parent().find('input.cme-negation-input').remove();
$(this).closest('td').find('input[type="checkbox"]').prop('checked',false);
$(this).closest('td').find('input.cme-negation-input').remove();

// Also apply for any other checkboxes with the same name
var cap_name_attr = $(this).next('input[type="checkbox"]').attr('name');
Expand All @@ -41,8 +41,8 @@ jQuery(document).ready( function($) {
cap_name_attr = $(this).next('label').find('input[type="checkbox"]').attr('name');
}

$('input[name="' + cap_name_attr + '"]').parent().closest('td').removeClass('cap-neg').removeClass('cap-yes').addClass('cap-no');
$('input[name="' + cap_name_attr + '"]').prop('checked',false).parent().find('input.cme-negation-input').remove();
$('input[name="' + cap_name_attr + '"]').closest('td').removeClass('cap-neg').removeClass('cap-yes').addClass('cap-no');
$('input[name="' + cap_name_attr + '"]').prop('checked',false).closest('td').find('input.cme-negation-input').remove();

if ($(this).closest('td').hasClass('capability-checkbox-rotate')) {
$(this).closest('td').find('input[type="checkbox"]').prop('checked', true);
Expand All @@ -51,8 +51,8 @@ jQuery(document).ready( function($) {
$('tr.unfiltered_upload').find('td').removeClass('cap-neg').removeClass('cap-yes').addClass('cap-no');
$('tr.unfiltered_upload').find('input[type="checkbox"]').prop('checked',false);
$('tr.unfiltered_upload').find('input.cme-negation-input').remove();
$('input[name="caps[unfiltered_upload]"]').parent().closest('td').removeClass('cap-neg').removeClass('cap-yes').addClass('cap-no');
$('input[name="caps[unfiltered_upload]"]').prop('checked', true).parent().find('input.cme-negation-input').remove();
$('input[name="caps[unfiltered_upload]"]').closest('td').removeClass('cap-neg').removeClass('cap-yes').addClass('cap-no');
$('input[name="caps[unfiltered_upload]"]').prop('checked', true).closest('td').find('input.cme-negation-input').remove();
}
}

Expand All @@ -61,8 +61,8 @@ jQuery(document).ready( function($) {
}

if ($(this).closest('tr').hasClass('unfiltered_upload')) {
$('input[name="caps[upload_files]"]').parent().closest('td').removeClass('cap-neg').removeClass('cap-yes').addClass('cap-no');
$('input[name="caps[upload_files]"]').prop('checked', true).parent().find('input.cme-negation-input').remove();
$('input[name="caps[upload_files]"]').closest('td').removeClass('cap-neg').removeClass('cap-yes').addClass('cap-no');
$('input[name="caps[upload_files]"]').prop('checked', true).closest('td').find('input.cme-negation-input').remove();
}
return false;
});
Expand Down
2 changes: 1 addition & 1 deletion common/js/admin.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions includes-core/CoreAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function __construct() {
function ($settings) {
$settings['publishpress-capabilities'] = [
'parent' => 'pp-capabilities-dashboard',
'label' => 'Upgrade to Pro',
'label' => __('Upgrade to Pro', 'capability-manager-enhanced'),
'link' => 'https://publishpress.com/links/capabilities-menu',
];

Expand Down Expand Up @@ -125,4 +125,4 @@ function frontendFeaturesPagesPromo(){
</div>
<?php
}
}
}
29 changes: 28 additions & 1 deletion includes/admin-load.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ function __construct() {
add_action('init', [$this, 'featureRestrictionsGutenberg'], PHP_INT_MAX - 1);

if (is_admin()) {
// Redirect on plugin activation
add_action('admin_init', [$this, 'redirect_on_activate'], 2000);

add_action('admin_init', [$this, 'featureRestrictionsClassic'], PHP_INT_MAX - 1);
add_action('wp_ajax_save_dashboard_feature_by_ajax', [$this, 'saveDashboardFeature']);

Expand Down Expand Up @@ -481,6 +484,16 @@ function cmeSubmenus() {
$cap_page_slug = false;
$cap_title = __('Capabilities', 'capability-manager-enhanced');
$cap_name = false;

//remove caps that doesn't have menu
if (in_array('manage_capabilities_user_testing', $user_menu_caps)) {
$cap_key = array_search('manage_capabilities_user_testing', $user_menu_caps);
if ($cap_key !== false) {
unset($user_menu_caps[$cap_key]);
$user_menu_caps = array_filter($user_menu_caps);
}
}

if (is_multisite() && is_super_admin()) {
$cap_name = 'read';
$cap_callback = [$this, 'dashboardPage'];
Expand Down Expand Up @@ -738,5 +751,19 @@ function ($value) use ($searchPrefix) {
</div>

<?php
}
}

/**
* Redirect user on plugin activation
*
* @return void
*/
public function redirect_on_activate()
{
if (get_option('pp_capabilities_activated')) {
delete_option('pp_capabilities_activated');
wp_safe_redirect(admin_url("admin.php?page=pp-capabilities-dashboard"));
exit;
}
}
}
71 changes: 50 additions & 21 deletions includes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
$sidebar_metabox_state['how_to_user_capabilities'] = 'opened';
}

if (!isset($sidebar_metabox_state['multi_site'])) {
$sidebar_metabox_state['multi_site'] = 'opened';
}
$roles = $this->roles;
$default = $this->current;

Expand Down Expand Up @@ -214,7 +217,7 @@
$cap_properties['delete']['type'] = array( 'delete_posts', 'delete_others_posts' );
$cap_properties['delete']['type'] = array_merge( $cap_properties['delete']['type'], array( 'delete_published_posts', 'delete_private_posts' ) );

if (defined('PRESSPERMIT_PRO_FILE')) {
if (defined('PRESSPERMIT_VERSION') && defined('PRESSPERMIT_COLLAB_VERSION')) {
$cap_properties['list']['type'] = ['list_posts', 'list_others_posts', 'list_published_posts', 'list_private_posts'];
}

Expand All @@ -240,7 +243,7 @@
'taxonomies' => __( 'Taxonomies', 'capability-manager-enhanced' ),
);

if (defined('PRESSPERMIT_PRO_FILE')) {
if (defined('PRESSPERMIT_VERSION') && defined('PRESSPERMIT_COLLAB_VERSION')) {
$cap_type_names['list'] = __('Listing', 'capability-manager-enhanced');
}

Expand Down Expand Up @@ -270,7 +273,7 @@
'manage_categories'
);

if (defined('PRESSPERMIT_PRO_FILE')) {
if (defined('PRESSPERMIT_PRO_FILE') && defined('PRESSPERMIT_COLLAB_VERSION')) {
$default_caps = array_merge($default_caps, ['list_posts', 'list_others_posts', 'list_published_posts', 'list_private_posts', 'list_pages', 'list_others_pages', 'list_published_pages', 'list_private_pages']);
}

Expand Down Expand Up @@ -757,8 +760,8 @@
|| $type_obj->cap->$prop == str_replace( '_posts', "_" . _cme_get_plural($type_obj->name, $type_obj), $prop )
|| $type_obj->cap->$prop == str_replace( '_pages', "_" . _cme_get_plural($type_obj->name, $type_obj), $prop )
)
&& (!in_array($type_obj->cap->$prop, $grouped_caps_lists)) //capabilitiy not enforced in $grouped_caps_lists
&& $type_obj->cap->$prop !== 'manage_post_tags'
&& (!in_array($type_obj->cap->$prop, $grouped_caps_lists)) //capability not enforced in $grouped_caps_lists
&& (('manage_post_tags' != $type_obj->cap->$prop) || (defined('PRESSPERMIT_ACTIVE') && in_array( $type_obj->name, cme_get_assisted_taxonomies())))
) {
// only present these term caps up top if we are ensuring that they get enforced separately from manage_terms
if ( in_array( $prop, array( 'edit_terms', 'delete_terms', 'assign_terms' ) ) && ( ! in_array( $type_obj->name, cme_get_detailed_taxonomies() ) || defined( 'OLD_PRESSPERMIT_ACTIVE' ) ) ) {
Expand Down Expand Up @@ -813,8 +816,7 @@
$cap_name = sanitize_text_field($type_obj->cap->$prop);
$cap_title = '';


if ($cap_name === 'manage_categories') {
if (($cap_name === 'manage_categories') && !defined('PRESSPERMIT_ACTIVE')) {
$tool_tip = sprintf(__( 'This capability is controlled by %s', 'capability-manager-enhanced' ), '<strong>manage_categories</strong>' );

} else {
Expand Down Expand Up @@ -904,7 +906,7 @@

echo '</table>';

if ($cap_type === 'list' && (defined('PRESSPERMIT_VERSION') || defined('PRESSPERMIT_PRO_VERSION'))) {
if ($cap_type === 'list' && defined('PRESSPERMIT_VERSION') && defined('PRESSPERMIT_COLLAB_VERSION')) {
echo '<p class="pp-subtext"> '. esc_html__('Admin listing access is normally provided by the "Edit" capabilities. These "List" capabilities only apply if the corresponding "Edit" capability is missing. Also, these "List" capabilities can grant access, but not deny access.', 'capability-manager-enhanced') .' </p>';
}

Expand Down Expand Up @@ -1393,7 +1395,7 @@
uasort( $this->capabilities, 'strnatcasecmp' ); // sort by array values, but maintain keys );

$additional_caps = apply_filters('publishpress_caps_manage_additional_caps', $this->capabilities);

$caps_empty = true;
foreach ($additional_caps as $cap_name => $cap) :
$cap_name = sanitize_text_field($cap_name);

Expand Down Expand Up @@ -1455,6 +1457,8 @@
$disabled = ' disabled ';
}
}

$caps_empty = false;
?>
<td class="<?php echo esc_attr($class); ?>"><span class="ppc-tool-tip disabled cap-x">X</span><span class="ppc-tool-tip disabled"><label><input type="checkbox" name="caps[<?php echo esc_attr($cap_name); ?>]" class="pp-single-action-rotate" autocomplete="off" value="1" <?php echo esc_attr($checked) . ' ' . esc_attr($disabled);?> />
<span>
Expand Down Expand Up @@ -1490,7 +1494,15 @@
}
}
?>

<?php if ($caps_empty) : ?>
<tr>
<td colspan="<?php echo (int) $checks_per_row;?>">
<div>
<?php esc_html_e( 'You have no additional capabilities.', 'capability-manager-enhanced' ); ?>
</div>
</td>
</tr>
<?php endif; ?>
<tr class="cme-bulk-select">
<td colspan="<?php echo (int) $checks_per_row;?>">
<input type="checkbox" class="cme-check-all" autocomplete="off" title="<?php esc_attr_e('check / uncheck all', 'capability-manager-enhanced');?>"> <span><?php _e('Capability Name', 'capability-manager-enhanced');?></span>
Expand Down Expand Up @@ -1633,6 +1645,31 @@ class="metabox-state"
</div>
</div>

<?php if (is_multisite() && is_super_admin() && is_main_site()) : ?>
<div class="ppc-sidebar-panel-metabox meta-box-sortables ppc-multi-site">
<?php $meta_box_state = (isset($sidebar_metabox_state['multi_site'])) ? $sidebar_metabox_state['multi_site'] : 'closed'; ?>
<div class="postbox ppc-sidebar-panel <?php echo esc_attr($meta_box_state); ?>">
<input
name="ppc_metabox_state[multi_site]"
type="hidden"
class="metabox-state"
value="<?php echo esc_attr($meta_box_state); ?>"
/>
<div class="postbox-header">
<h2 class="hndle ui-sortable-handle"><?php esc_html_e('Multisite', 'capability-manager-enhanced'); ?></h2>
<div class="handle-actions">
<button type="button" class="handlediv">
<span class="toggle-indicator"></span>
</button>
</div>
</div>
<div class="inside">
<?php cme_network_role_ui( $default ); ?>
</div>
</div>
</div>
<?php endif; ?>

<?php
do_action('publishpress-caps_sidebar_bottom');
?>
Expand Down Expand Up @@ -1762,11 +1799,6 @@ class="metabox-state"

</div>

<?php
$support_pp_only_roles = defined('PRESSPERMIT_ACTIVE');
cme_network_role_ui( $default );
?>

<p class="submit" style="padding-top:0;">
<input type="hidden" name="action" value="update" />
<input type="hidden" name="current" value="<?php echo esc_attr($default); ?>" />
Expand Down Expand Up @@ -1795,22 +1827,19 @@ function cme_network_role_ui( $default ) {
return false;
}
?>

<div style="float:right;margin-left:10px;margin-right:10px">
<?php
if ( ! $autocreate_roles = get_site_option( 'cme_autocreate_roles' ) )
$autocreate_roles = array();
?>
<div style="margin-bottom: 5px">
<label for="cme_autocreate_role" title="<?php esc_attr_e('Create this role definition in new (future) sites', 'capability-manager-enhanced');?>"><input type="checkbox" name="cme_autocreate_role" id="cme_autocreate_role" autocomplete="off" value="1" <?php echo checked(in_array($default, $autocreate_roles));?>> <?php esc_html_e('include in new sites', 'capability-manager-enhanced'); ?> </label>
<label for="cme_autocreate_role" title="<?php esc_attr_e('Create this role definition in new (future) sites', 'capability-manager-enhanced');?>"><input type="checkbox" name="cme_autocreate_role" id="cme_autocreate_role" autocomplete="off" value="1" <?php echo checked(in_array($default, $autocreate_roles));?>> <?php esc_html_e('Include in new sites.', 'capability-manager-enhanced'); ?> </label>
</div>
<div>
<label for="cme_net_sync_role" title="<?php echo esc_attr__('Copy / update this role definition to all sites now', 'capability-manager-enhanced');?>"><input type="checkbox" name="cme_net_sync_role" id="cme_net_sync_role" autocomplete="off" value="1"> <?php esc_html_e('sync role to all sites now', 'capability-manager-enhanced'); ?> </label>
<label for="cme_net_sync_role" title="<?php echo esc_attr__('Copy / update this role definition to all sites now', 'capability-manager-enhanced');?>"><input type="checkbox" name="cme_net_sync_role" id="cme_net_sync_role" autocomplete="off" value="1"> <?php esc_html_e('Sync role to all sites.', 'capability-manager-enhanced'); ?> </label>
</div>
<div>
<label for="cme_net_sync_options" title="<?php echo esc_attr__('Copy option settings to all sites now', 'capability-manager-enhanced');?>"><input type="checkbox" name="cme_net_sync_options" id="cme_net_sync_options" autocomplete="off" value="1"> <?php esc_html_e('sync options to all sites now', 'capability-manager-enhanced'); ?> </label>
<label for="cme_net_sync_options" title="<?php echo esc_attr__('Copy option settings to all sites now', 'capability-manager-enhanced');?>"><input type="checkbox" name="cme_net_sync_options" id="cme_net_sync_options" autocomplete="off" value="1"> <?php esc_html_e('Sync options to all sites.', 'capability-manager-enhanced'); ?> </label>
</div>
</div>
<?php
return true;
}
Expand Down
9 changes: 3 additions & 6 deletions includes/cap-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,12 @@ function force_distinct_taxonomy_caps() {
}
$tx_caps = (array) $wp_taxonomies[$taxonomy]->cap;


// Optionally, also force edit_terms and delete_terms to be distinct from manage_terms, and force a distinct assign_terms capability
if ( in_array( $taxonomy, $detailed_taxonomies ) ) {
foreach( $tx_detail_caps as $cap_property => $replacement_cap_format ) {
$tx_cap_usage = array_count_values($tx_caps);

// If a unique edit/delete capability is already defined, don't change the definition
if (!empty($tx_caps[$cap_property])
if ( !empty($tx_caps[$cap_property])
&& (empty($this->all_taxonomy_caps[$tx_caps[$cap_property]]) || $this->all_taxonomy_caps[$tx_caps[$cap_property]] == 1)
&& ($tx_cap_usage[$tx_caps[$cap_property]] == 1)
&& !defined('CAPSMAN_LEGACY_DETAILED_TAX_CAPS')
Expand All @@ -310,7 +308,7 @@ function force_distinct_taxonomy_caps() {
$custom_detailed_taxonomy_caps = true;
$generated_cap_name = str_replace('_terms', "_{$plural_type}", $replacement_cap_format);

if (!get_option("cme_migrated_taxonomy_caps")) {
if (!empty(get_option("cme_migrated_taxonomy_caps"))) {
foreach ($wp_roles->roles as $role_name => $role) {
if (!empty($role['capabilities'][$generated_cap_name])) {
$_role = get_role($role_name);
Expand Down Expand Up @@ -340,9 +338,8 @@ function force_distinct_taxonomy_caps() {
}
}
}

if (!empty($custom_detailed_taxonomy_caps)) {
update_option("cme_migrated_taxonomy_caps", true);
update_option("cme_migrated_taxonomy_caps", '1');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public static function frontendElementNewEntryAjaxHandler()
$response['content'] = '';

$custom_label = isset($_POST['custom_label']) ? sanitize_text_field($_POST['custom_label']) : '';
$custom_element_selector = isset($_POST['custom_element_selector']) ? sanitize_textarea_field($_POST['custom_element_selector']) : '';
$custom_element_styles = isset($_POST['custom_element_styles']) ? sanitize_textarea_field($_POST['custom_element_styles']) : '';
$custom_element_selector = isset($_POST['custom_element_selector']) ? stripslashes_deep(sanitize_textarea_field($_POST['custom_element_selector'])) : '';
$custom_element_styles = isset($_POST['custom_element_styles']) ? stripslashes_deep(sanitize_textarea_field($_POST['custom_element_styles'])) : '';
$custom_element_bodyclass = isset($_POST['custom_element_bodyclass']) ? sanitize_textarea_field($_POST['custom_element_bodyclass']) : '';
$element_pages = (isset($_POST['element_pages']) && is_array($_POST['element_pages'])) ? array_map('sanitize_text_field', $_POST['element_pages']) : [];
$element_post_types = (isset($_POST['element_post_types']) && is_array($_POST['element_post_types'])) ? array_map('sanitize_text_field', $_POST['element_post_types']) : [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ public function setFrontendFeaturesRestrictionGlobal()

$cache_key = 'ppc_ff_page_restriction_cache';

$page_restriction_data = wp_cache_get($cache_key, 'data');
/**
* Filter if frontend feature should use cache data.
* Check https://github.com/publishpress/PublishPress-Capabilities/issues/1152
* @var mixed
*/
$use_cache_data = apply_filters('pp_capabilities_frontend_feature_cache', true);

$page_restriction_data = $use_cache_data ? wp_cache_get($cache_key, 'data') : false;

if ($page_restriction_data && is_array($page_restriction_data)) {
//use cache data
Expand Down
Loading

0 comments on commit 10696be

Please sign in to comment.