Capability Manager Enhanced - Version 1.7.3

Version Description

  • 9 Apr 2019
Download this release

Release Info

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

Code changes from version 1.7.2 to 1.7.3

capsman-enhanced.php CHANGED
@@ -3,7 +3,7 @@
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.7.2
7
* Author: PublishPress
8
* Author URI: https://publishpress.com
9
* Text Domain: capsman-enhanced
@@ -23,12 +23,12 @@
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.7.2
27
*/
28
29
if ( ! defined( 'CAPSMAN_VERSION' ) ) {
30
- define( 'CAPSMAN_VERSION', '1.7.2' );
31
- define( 'CAPSMAN_ENH_VERSION', '1.7.2' );
32
}
33
34
if ( cme_is_plugin_active( 'capsman.php' ) ) {
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.7.3
7
* Author: PublishPress
8
* Author URI: https://publishpress.com
9
* Text Domain: capsman-enhanced
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.7.3
27
*/
28
29
if ( ! defined( 'CAPSMAN_VERSION' ) ) {
30
+ define( 'CAPSMAN_VERSION', '1.7.3' );
31
+ define( 'CAPSMAN_ENH_VERSION', '1.7.3' );
32
}
33
34
if ( cme_is_plugin_active( 'capsman.php' ) ) {
includes/admin.php CHANGED
@@ -25,7 +25,7 @@
25
* along with this program. If not, see <http://www.gnu.org/licenses/>.
26
**/
27
28
- global $capsman, $cme_cap_helper;
29
30
$roles = $this->roles;
31
$default = $this->current;
@@ -572,9 +572,10 @@ if( defined('PRESSPERMIT_ACTIVE') ) {
572
foreach ( $this->capabilities as $cap_name => $cap ) :
573
if ( isset( $type_caps[$cap_name] ) || isset($core_caps[$cap_name]) )
574
continue;
575
-
576
- if ( ! $is_administrator && ! current_user_can($cap_name) )
577
continue;
578
579
// ============ End Kevin B mod ===============
580
25
* along with this program. If not, see <http://www.gnu.org/licenses/>.
26
**/
27
28
+ global $capsman, $cme_cap_helper, $current_user;
29
30
$roles = $this->roles;
31
$default = $this->current;
572
foreach ( $this->capabilities as $cap_name => $cap ) :
573
if ( isset( $type_caps[$cap_name] ) || isset($core_caps[$cap_name]) )
574
continue;
575
+
576
+ if ( ! $is_administrator && empty( $current_user->allcaps[$cap_name] ) ) {
577
continue;
578
+ }
579
580
// ============ End Kevin B mod ===============
581
includes/filters-admin.php ADDED
@@ -0,0 +1,38 @@
1
+ <?php
2
+ class CME_AdminMenuNoPrivWorkaround {
3
+ var $create_posts_cap = '';
4
+
5
+ function __construct() {
6
+ global $pagenow;
7
+
8
+ if ( 'edit.php' == $pagenow ) {
9
+ // Prevent lack of create_posts capability from completely blocking admin menu access to a post type.
10
+ // The "Add New" page is already successfully blocked by other means.
11
+ add_action( '_admin_menu', array( $this, 'menu_nopriv_workaround_enable' ), PHP_INT_MAX );
12
+ add_action( 'admin_menu', array( $this, 'menu_nopriv_workaround_disable' ), PHP_INT_MIN );
13
+ }
14
+ }
15
+
16
+ function menu_nopriv_workaround_enable() {
17
+ global $typenow;
18
+
19
+ if ( $post_type_obj = get_post_type_object( $typenow ) ) {
20
+ $this->create_posts_cap = $post_type_obj->cap->create_posts;
21
+ add_filter( 'user_has_cap', array( $this, 'admin_menu_caps' ), PHP_INT_MAX, 3 );
22
+ }
23
+ }
24
+
25
+ function menu_nopriv_workaround_disable() {
26
+ if ( $this->create_posts_cap ) {
27
+ remove_filter( 'user_has_cap', array( $this, 'admin_menu_caps' ), PHP_INT_MAX, 3 );
28
+ }
29
+ }
30
+
31
+ function admin_menu_caps( $wp_sitecaps, $reqd_caps, $args ) {
32
+ if ( is_array($args) && isset($args[0]) && ( $this->create_posts_cap == $args[0] ) ) {
33
+ $wp_sitecaps[ $args[0] ] = true;
34
+ }
35
+
36
+ return $wp_sitecaps;
37
+ }
38
+ } // end class
includes/filters.php CHANGED
@@ -26,6 +26,14 @@ if ( defined( 'WC_PLUGIN_FILE' ) ) {
26
$cme_extensions->add( new CME_WooCommerce() );
27
}
28
29
// allow edit_terms, delete_terms, assign_terms capabilities to function separately from manage_terms
30
function _cme_remap_term_meta_cap ( $caps, $cap, $user_id, $args ) {
31
global $current_user, $cme_cap_helper;
26
$cme_extensions->add( new CME_WooCommerce() );
27
}
28
29
+ if ( is_admin() ) {
30
+ global $pagenow;
31
+ if ( 'edit.php' == $pagenow ) {
32
+ require_once ( dirname(__FILE__) . '/filters-admin.php' );
33
+ new CME_AdminMenuNoPrivWorkaround();
34
+ }
35
+ }
36
+
37
// allow edit_terms, delete_terms, assign_terms capabilities to function separately from manage_terms
38
function _cme_remap_term_meta_cap ( $caps, $cap, $user_id, $args ) {
39
global $current_user, $cme_cap_helper;
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: publishpress, kevinB, stevejburge, andergmartins
3
Tags: roles, capabilities, manager, editor, rights, role, capability, types, taxonomies, network, multisite, default
4
Requires at least: 4.1
5
Tested up to: 5.1
6
- Stable tag: 1.7.2
7
License: GPLv3
8
License URI: https://www.gnu.org/licenses/gpl-3.0.html
9
@@ -70,6 +70,10 @@ Keep in mind that this plugin's main purpose is to expose switches (defined capa
70
71
== Changelog ==
72
73
= 1.7.2 - 3 Apr 2019 =
74
* Compat : WooCommerce integration - Users lacking access to the "Add New Order" submenu could not access Posts, Pages, Products or any other Post Type listing. This occurred if "use create_posts" option enabled and user lacks the create capability for Orders.
75
3
Tags: roles, capabilities, manager, editor, rights, role, capability, types, taxonomies, network, multisite, default
4
Requires at least: 4.1
5
Tested up to: 5.1
6
+ Stable tag: 1.7.3
7
License: GPLv3
8
License URI: https://www.gnu.org/licenses/gpl-3.0.html
9
70
71
== Changelog ==
72
73
+ = 1.7.3 - 9 Apr 2019 =
74
+ * Fixed : Work around WP quirk of completely blocking admin page access for a post type if user lacks create capability for the post type and there are no other accessible items on the menu.
75
+ * Fixed : PHP Notices on Roles and Capabilities screen for non-Administrator with WooCommerce active
76
+
77
= 1.7.2 - 3 Apr 2019 =
78
* Compat : WooCommerce integration - Users lacking access to the "Add New Order" submenu could not access Posts, Pages, Products or any other Post Type listing. This occurred if "use create_posts" option enabled and user lacks the create capability for Orders.
79