Capability Manager Enhanced - Version 1.5.11

Version Description

  • Feature : Automatically save backup of WP roles on plugin activation or update
    • Feature : When roles are manually backed up, also retain initial role backup
    • Feature : Backup Tool can also display contents of role backups
Download this release

Release Info

Developer kevinB
Plugin Icon 128x128 Capability Manager Enhanced
Version 1.5.11
Comparing to
See all releases

Code changes from version 1.5.10 to 1.5.11

capsman-enhanced.php CHANGED
@@ -1,31 +1,34 @@
1
<?php
2
/**
3
- * Capability Manager. Main Plugin File.
4
- * Plugin to create and manage Roles and Capabilities.
5
*
6
* @package capability-manager-enhanced
7
- * @author Jordi Canals, Kevin Behrens
8
- * @copyright Copyright (C) 2009, 2010 Jordi Canals; modifications Copyright (C) 2012-2018 Kevin Behrens
9
* @license GNU General Public License version 3
10
- * @link http://agapetry.net
11
- * @version 1.5.10
12
*/
13
14
- /*
15
- Plugin Name: Capability Manager Enhanced
16
- Plugin URI: http://presspermit.com/capability-manager
17
- Description: Manage WordPress role definitions, per-site or network-wide. Organizes post capabilities by post type and operation.
18
- Version: 1.5.10
19
- Author: Jordi Canals, Kevin Behrens
20
- Author URI: http://agapetry.net
21
- Text Domain: capsman-enhanced
22
- Domain Path: /lang/
23
- License: GPLv3
24
- */
25
-
26
if ( ! defined( 'CAPSMAN_VERSION' ) ) {
27
- define( 'CAPSMAN_VERSION', '1.5.10' );
28
- define( 'CAPSMAN_ENH_VERSION', '1.5.10' );
29
}
30
31
if ( cme_is_plugin_active( 'capsman.php' ) ) {
1
<?php
2
/**
3
+ * Plugin Name: Capability Manager Enhanced
4
+ * Plugin URI: https://publishpress.com
5
+ * Description: Manage WordPress role definitions, per-site or network-wide. Organizes post capabilities by post type and operation.
6
+ * Version: 1.5.11
7
+ * Author: PublishPress
8
+ * Author URI: https://publishpress.com
9
+ * Text Domain: capsman-enhanced
10
+ * Domain Path: /lang/
11
+ * License: GPLv3
12
+ *
13
+ * Copyright (c) 2019 PublishPress
14
+ *
15
+ * ------------------------------------------------------------------------------
16
+ * Based on Capability Manager
17
+ * Author: Jordi Canals
18
+ * Copyright (c) 2009, 2010 Jordi Canals
19
+ * ------------------------------------------------------------------------------
20
*
21
* @package capability-manager-enhanced
22
+ * @author PublishPress
23
+ * @copyright Copyright (C) 2009, 2010 Jordi Canals; modifications Copyright (C) 2019 PublishPress
24
* @license GNU General Public License version 3
25
+ * @link https://publishpress.com
26
+ * @version 1.5.11
27
*/
28
29
if ( ! defined( 'CAPSMAN_VERSION' ) ) {
30
+ define( 'CAPSMAN_VERSION', '1.5.11' );
31
+ define( 'CAPSMAN_ENH_VERSION', '1.5.11' );
32
}
33
34
if ( cme_is_plugin_active( 'capsman.php' ) ) {
framework/classes/abstract/plugin.php CHANGED
@@ -138,9 +138,6 @@ abstract class akPluginAbstract
138
{
139
$this->pluginActivate();
140
141
- // Save options and version
142
- add_option($this->ID . '_version', $this->version);
143
-
144
// Do activated hook.
145
do_action('ak_activate_' . $this->ID . '_plugin');
146
}
@@ -163,7 +160,7 @@ abstract class akPluginAbstract
163
$version = get_option($this->ID . '_version');
164
$this->pluginUpdate($version);
165
166
- update_option($this->ID . '_version', $this->version);
167
168
do_action('ak_' . $this->ID . '_updated');
169
}
@@ -212,7 +209,7 @@ abstract class akPluginAbstract
212
213
$url = apply_filters('ak_' . $this->ID . '_style_admin', $url);
214
if ( ! empty($url) ) {
215
- wp_register_style('ak_' . $this->ID . '_admin', $url, array('ak_framework_admin'), $this->version);
216
wp_enqueue_style('ak_' . $this->ID . '_admin');
217
}
218
@@ -245,8 +242,8 @@ abstract class akPluginAbstract
245
if ( ! isset($this->ID) )
246
$this->ID = ( empty($id) ) ? strtolower(basename($this->mod_file, '.php')) : trim($id) ;
247
248
- $old_version = get_option($this->ID . '_version');
249
- if ( version_compare($old_version, $this->version, 'ne') ) {
250
$this->needs_update = true;
251
}
252
}
138
{
139
$this->pluginActivate();
140
141
// Do activated hook.
142
do_action('ak_activate_' . $this->ID . '_plugin');
143
}
160
$version = get_option($this->ID . '_version');
161
$this->pluginUpdate($version);
162
163
+ update_option($this->ID . '_version', CAPSMAN_ENH_VERSION);
164
165
do_action('ak_' . $this->ID . '_updated');
166
}
209
210
$url = apply_filters('ak_' . $this->ID . '_style_admin', $url);
211
if ( ! empty($url) ) {
212
+ wp_register_style('ak_' . $this->ID . '_admin', $url, array('ak_framework_admin'), CAPSMAN_ENH_VERSION);
213
wp_enqueue_style('ak_' . $this->ID . '_admin');
214
}
215
242
if ( ! isset($this->ID) )
243
$this->ID = ( empty($id) ) ? strtolower(basename($this->mod_file, '.php')) : trim($id) ;
244
245
+ $old_version = get_option($this->ID . '_version');
246
+ if ( version_compare($old_version, CAPSMAN_ENH_VERSION, 'ne') ) {
247
$this->needs_update = true;
248
}
249
}
includes/backup-handler.php CHANGED
@@ -23,14 +23,37 @@ class Capsman_BackupHandler
23
24
global $wpdb;
25
$wp_roles = $wpdb->prefix . 'user_roles';
26
- $cm_roles = 'capsman_backup';
27
28
switch ( $_POST['action'] ) {
29
case 'backup':
30
$roles = get_option($wp_roles);
31
- update_option($cm_roles, $roles);
32
ak_admin_notify(__('New backup saved.', 'capsman-enhanced'));
33
break;
34
case 'restore':
35
$roles = get_option($cm_roles);
36
if ( $roles ) {
23
24
global $wpdb;
25
$wp_roles = $wpdb->prefix . 'user_roles';
26
+ $cm_roles = $this->cm->ID . '_backup';
27
+ $cm_roles_initial = $this->cm->ID . '_backup_initial';
28
29
switch ( $_POST['action'] ) {
30
case 'backup':
31
+ if ( ! get_option( $cm_roles_initial ) ) {
32
+ if ( $current_backup = get_option( $cm_roles ) ) {
33
+ update_option( $cm_roles_initial, $current_backup, false );
34
+
35
+ if ( $initial_datestamp = get_option( $this->cm->ID . '_backup_datestamp' ) ) {
36
+ update_option($this->cm->ID . '_backup_initial_datestamp', $initial_datestamp, false );
37
+ }
38
+ }
39
+ }
40
+
41
$roles = get_option($wp_roles);
42
+ update_option($cm_roles, $roles, false);
43
+ update_option($this->cm->ID . '_backup_datestamp', current_time( 'timestamp' ), false );
44
ak_admin_notify(__('New backup saved.', 'capsman-enhanced'));
45
break;
46
+
47
+ case 'restore_initial':
48
+ $roles = get_option($cm_roles_initial);
49
+ if ( $roles ) {
50
+ update_option($wp_roles, $roles);
51
+ ak_admin_notify(__('Roles and Capabilities restored from initial backup.', 'capsman-enhanced'));
52
+ } else {
53
+ ak_admin_error(__('Restore failed. No backup found.', 'capsman-enhanced'));
54
+ }
55
+ break;
56
+
57
case 'restore':
58
$roles = get_option($cm_roles);
59
if ( $roles ) {
includes/backup.php CHANGED
@@ -47,6 +47,12 @@
47
<td>
48
<select name="action">
49
<option value="backup"> <?php _e('Backup roles and capabilities', 'capsman-enhanced'); ?> </option>
50
<option value="restore"> <?php _e('Restore last saved backup', 'capsman-enhanced'); ?> </option>
51
</select> &nbsp;
52
<input type="submit" name="Perform" value="<?php _e('Do Action', 'capsman-enhanced') ?>" class="button-primary" />
@@ -54,6 +60,77 @@
54
</tr>
55
</table>
56
</dd>
57
</dl>
58
59
<dl>
47
<td>
48
<select name="action">
49
<option value="backup"> <?php _e('Backup roles and capabilities', 'capsman-enhanced'); ?> </option>
50
+
51
+ <?php
52
+ if ( $initial = get_option( 'capsman_backup_initial' ) ):?>
53
+ <option value="restore_initial"> <?php _e('Restore initial backup', 'capsman-enhanced'); ?> </option>
54
+ <?php endif;?>
55
+
56
<option value="restore"> <?php _e('Restore last saved backup', 'capsman-enhanced'); ?> </option>
57
</select> &nbsp;
58
<input type="submit" name="Perform" value="<?php _e('Do Action', 'capsman-enhanced') ?>" class="button-primary" />
60
</tr>
61
</table>
62
</dd>
63
+
64
+ <p>&nbsp;
65
+ <?php if( ! empty( $initial ) ):?>
66
+ <a id="cme_show_initial" href="javascript:void(0)"><?php _e('Show initial backup', 'capsman-enhanced');?></a> &nbsp;&bull;&nbsp;
67
+ <?php endif;?>
68
+ <a id="cme_show_last" href="javascript:void(0)"><?php _e('Show last backup', 'capsman-enhanced');?></a>
69
+ </p>
70
+
71
+ <script type="text/javascript">
72
+ /* <![CDATA[ */
73
+ jQuery(document).ready( function($) {
74
+ $( '#cme_show_initial').click( function() {
75
+ $('#cme_display_capsman_backup_initial').show();
76
+ $('#cme_display_capsman_backup').hide();
77
+ });
78
+ $( '#cme_show_last').click( function() {
79
+ $('#cme_display_capsman_backup_initial').hide();
80
+ $('#cme_display_capsman_backup').show();
81
+ });
82
+ });
83
+ /* ]]> */
84
+ </script>
85
+
86
+ <?php
87
+ global $wp_roles;
88
+
89
+ $initial_caption = ( $backup_datestamp = get_option( 'capsman_backup_initial_datestamp' ) ) ? sprintf( __('Initial Backup - %s', 'capsman-enhanced'), date( 'j M Y, g:i a', $backup_datestamp ) ) : __('Initial Backup', 'capsman-enhanced');
90
+ $last_caption = ( $backup_datestamp = get_option( 'capsman_backup_datestamp' ) ) ? sprintf( __('Last Backup - %s', 'capsman-enhanced'), date( 'j M Y, g:i a', $backup_datestamp ) ) : __('Last Backup', 'capsman-enhanced');
91
+
92
+ $backups = array(
93
+ 'capsman_backup_initial' => $initial_caption,
94
+ 'capsman_backup' => $last_caption,
95
+ );
96
+
97
+ foreach( $backups as $name => $caption ) {
98
+ if ( $backup_data = get_option( $name ) ) :?>
99
+ <div id="cme_display_<?php echo $name;?>" style="display:none;padding-left:20px;">
100
+ <h3><?php printf( __( "%s (%s roles)", 'capsman-enhanded' ), $caption, count($backup_data) ); ?></h3>
101
+
102
+ <?php foreach( $backup_data as $role => $props ) :?>
103
+ <?php if ( ! isset( $props['name'] ) ) continue;?>
104
+ <?php
105
+ $level = 0;
106
+ for( $i=10; $i>=0; $i--) {
107
+ if ( ! empty( $props['capabilities']["level_{$i}"] ) ) {
108
+ $level = $i;
109
+ break;
110
+ }
111
+ }
112
+ ?>
113
+ <?php
114
+ $role_caption = $props['name'];
115
+ if ( empty( $wp_roles->role_objects[$role] ) ) $role_caption = "<span class='cme-plus' style='color:green;font-weight:800'>$role_caption</span>";?>
116
+ <h4><?php printf( __( '%s (level %s)', 'capsman-enhanced' ), $role_caption, $level );?></h4>
117
+ <ul style="list-style:disc;padding-left:30px">
118
+
119
+ <?php
120
+ ksort( $props['capabilities'] );
121
+ foreach( $props['capabilities'] as $cap_name => $val ) :
122
+ if ( 0 === strpos( $cap_name, 'level_' ) ) continue;
123
+ ?>
124
+ <?php if ( $val && ( empty( $wp_roles->role_objects[$role] ) || empty( $wp_roles->role_objects[$role]->capabilities[$cap_name] ) ) ) $cap_name = "<span class='cme-plus' style='color:green;font-weight:800'>$cap_name</span>";?>
125
+ <li><?php echo ( $val ) ? $cap_name : "<strike>$cap_name</strike>";?></li>
126
+ <?php endforeach;?>
127
+
128
+ </ul>
129
+ <?php endforeach;?>
130
+ </div>
131
+ <?php endif;
132
+ }
133
+ ?>
134
</dl>
135
136
<dl>
includes/manager.php CHANGED
@@ -152,7 +152,8 @@ class CapabilityManager extends akPluginAbstract
152
if ( false === $backup ) { // No previous backup found. Save it!
153
global $wpdb;
154
$roles = get_option($wpdb->prefix . 'user_roles');
155
- update_option($this->ID . '_backup', $roles);
156
}
157
}
158
152
if ( false === $backup ) { // No previous backup found. Save it!
153
global $wpdb;
154
$roles = get_option($wpdb->prefix . 'user_roles');
155
+ update_option( $this->ID . '_backup', $roles, false );
156
+ update_option( $this->ID . '_backup_datestamp', current_time( 'timestamp' ), false );
157
}
158
}
159
readme.txt CHANGED
@@ -1,10 +1,9 @@
1
=== Capability Manager Enhanced===
2
- Contributors: txanny, kevinB
3
- Donate Link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=JWZVFUDLLYQBA
4
Tags: roles, capabilities, manager, editor, rights, role, capability, types, taxonomies, network, multisite, default
5
Requires at least: 3.1
6
- Tested up to: 4.9.8
7
- Stable tag: 1.5.10
8
9
A simple way to manage WordPress roles and capabilities.
10
@@ -17,56 +16,25 @@ Capability Manager Enhanced provides a simple way to manage WordPress role defin
17
* Create roles
18
* Manage role capabilities
19
* Supports negation: set any capability to granted, not granted, or blocked
20
- * Copy any role all network sites
21
* Mark any role for auto-copy to future network sites
22
* Backup and restore Roles and Capabilities to revert your last changes.
23
* Revert Roles and Capabilities to WordPress defaults.
24
25
- Role management can also be delegated:
26
-
27
- * Only users with 'manage_capabilities' can manage them. This capability is created at install time and assigned to Administrators.
28
- * Administrator role cannot be deleted.
29
- * Non-administrators can only manage roles or users with same or lower capabilities.
30
-
31
- Enhanced and supported by <a href="http://agapetry.net">Kevin Behrens</a> since July 2012. The original Capability Manager author, Jordi Canals, has not updated the plugin since early 2010. Since he was unreachable by web or email, I decided to take on the project myself.
32
33
- The main change from the original plugin is an improved UI which organizes capabilities:
34
35
- * by post type
36
- * by operation (read/edit/delete)
37
- * by origin (WP core or plugin)
38
-
39
- Capability Manager Enhanced also adds <a href="http://wordpress.org/plugins/press-permit-core">Press Permit</a> plugin integration:
40
41
* easily specify which post types require type-specific capability definitions
42
* show capabilities which Press Permit adds to the role by supplemental type-specific role assignment
43
-
44
- = Languages included: =
45
-
46
- * English
47
- * Catalan
48
- * Spanish
49
- * Belorussian *by <a href="http://antsar.info/" rel="nofollow">Ilyuha</a>*
50
- * German *by <a href="http://great-solution.de/" rel="nofollow">Carsten Tauber</a>*
51
- * Italian *by <a href="http://gidibao.net" rel="nofollow">Gianni Diurno</a>*
52
- * Russian *by <a href="http://www.fatcow.com" rel="nofollow">Marcis Gasuns</a>*
53
- * Swedish *by <a href="http://jenswedin.com/" rel="nofollow">Jens Wedin</a>
54
- * POT file for easy translation to other languages included.
55
-
56
- == Installation ==
57
-
58
- = System Requirements =
59
60
- * **Requires PHP 5.2**. Older versions of PHP are obsolete and expose your site to security risks.
61
- * Verify the plugin is compatible with your WordPress Version. If not, plugin will not load.
62
-
63
- = Installing the plugin =
64
65
- 1. Unzip the plugin archive.
66
- 1. Upload the plugin's folder to the WordPress plugins directory.
67
- 1. Activate the plugin through the 'Plugins' menu in WordPress.
68
- 1. Manage the capabilities on the 'Capabilities' page on Users menu.
69
- 1. Enjoy your plugin!
70
71
== Screenshots ==
72
@@ -96,19 +64,13 @@ Keep in mind that this plugin's purpose is to conveniently view and modify the c
96
97
* If you need help, <a href="http://wordpress.org/tags/capsman-enhanced">ask in the Support forum</a>. If your issue pertains to the enforcement of assigned capabilities, I am not the primary support avenue. In many cases, I will offer a suggestion, but please don't give me negative feedback for not providing free consulting.
98
99
- == License ==
100
-
101
- Copyright 2009, 2010 Jordi Canals
102
- Copyright 2013-2018, Kevin Behrens
103
-
104
- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.
105
-
106
- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
107
-
108
- You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
109
-
110
== Changelog ==
111
112
= 1.5.10 =
113
* Fixed : Back button caused mismatching role dropdown selection
114
* Compat : PHP 7.2 - warning for deprecated function if a second copy of CME is activated
1
=== Capability Manager Enhanced===
2
+ Contributors: publishpress, kevinB, stevejburge, andergmartins
3
Tags: roles, capabilities, manager, editor, rights, role, capability, types, taxonomies, network, multisite, default
4
Requires at least: 3.1
5
+ Tested up to: 5.1
6
+ Stable tag: 1.5.11
7
8
A simple way to manage WordPress roles and capabilities.
9
16
* Create roles
17
* Manage role capabilities
18
* Supports negation: set any capability to granted, not granted, or blocked
19
+ * Copy any role to all network sites
20
* Mark any role for auto-copy to future network sites
21
* Backup and restore Roles and Capabilities to revert your last changes.
22
* Revert Roles and Capabilities to WordPress defaults.
23
24
+ Capability Manager Enhanced is professionally developed and supported by the experienced <a href="https://publishpress.com">PublishPress</a> team.
25
26
+ It has been a reliable tool since 2012, when PublishPress team member Kevin Behrens forked it from Jordi Canals' abandoned Capability Manager plugin.
27
28
+ When the WordPress roles and capabilities model is not enough, take advantage of <a href="https://wordpress.org/plugins/press-permit-core">Press Permit</a> plugin integration:
29
30
* easily specify which post types require type-specific capability definitions
31
* show capabilities which Press Permit adds to the role by supplemental type-specific role assignment
32
33
+ Role management can also be delegated:
34
35
+ * Only users with 'manage_capabilities' can manage them. This capability is created at install time and assigned to Administrators.
36
+ * Administrator role cannot be deleted.
37
+ * Non-administrators can only manage roles or users with same or lower capabilities.
38
39
== Screenshots ==
40
64
65
* If you need help, <a href="http://wordpress.org/tags/capsman-enhanced">ask in the Support forum</a>. If your issue pertains to the enforcement of assigned capabilities, I am not the primary support avenue. In many cases, I will offer a suggestion, but please don't give me negative feedback for not providing free consulting.
66
67
== Changelog ==
68
69
+ = 1.5.11 =
70
+ * Feature : Automatically save backup of WP roles on plugin activation or update
71
+ * Feature : When roles are manually backed up, also retain initial role backup
72
+ * Feature : Backup Tool can also display contents of role backups
73
+
74
= 1.5.10 =
75
* Fixed : Back button caused mismatching role dropdown selection
76
* Compat : PHP 7.2 - warning for deprecated function if a second copy of CME is activated