Esempio n. 1
0
function ure_getCapsToRemove()
{
    global $wp_roles, $wpdb;
    // build full capabilities list from all roles except Administrator
    $fullCapsList = array();
    foreach ($wp_roles->roles as $role) {
        // validate if capabilities is an array
        if (isset($role['capabilities']) && is_array($role['capabilities'])) {
            foreach ($role['capabilities'] as $capability => $value) {
                if (!isset($fullCapsList[$capability])) {
                    $fullCapsList[$capability] = 1;
                }
            }
        }
    }
    $capsToExclude = ure_getBuiltInWPCaps();
    $capsToRemove = array();
    foreach ($fullCapsList as $capability => $value) {
        if (!isset($capsToExclude[$capability])) {
            // check roles
            $capInUse = false;
            foreach ($wp_roles->role_objects as $wp_role) {
                if ($wp_role->name != 'administrator') {
                    if ($wp_role->has_cap($capability)) {
                        $capInUse = true;
                        break;
                    }
                }
            }
            if (!$capInUse) {
                $capsToRemove[$capability] = 1;
            }
        }
    }
    return $capsToRemove;
}
Esempio n. 2
0
/**
 * output HTML-code for capabilities list
 * @global boolean $ure_currentRole
 * @global type $ure_show_deprecated_caps
 * @global boolean $ure_roles
 * @global boolean $ure_fullCapabilities
 * @global type $ure_caps_readable
 * @param boolean $core - if true, then show WordPress core capabilities, else custom (plugins and themes created)
 * @param boolean $for_role - if true, it is role capabilities list, else - user specific capabilities list
 */
function ure_show_capabilities($core = true, $for_role = true)
{
    global $ure_currentRole, $ure_show_deprecated_caps, $ure_roles, $ure_fullCapabilities, $ure_caps_readable, $ure_userToEdit;
    $onclick_for_admin = '';
    if (!(is_multisite() && is_super_admin())) {
        // do not limit SuperAdmin for multi-site
        if ($core && 'administrator' == $ure_currentRole) {
            $onclick_for_admin = 'onclick="turn_it_back(this)"';
        }
    }
    if ($core) {
        $quant = count(ure_getBuiltInWPCaps());
        $deprecatedCaps = ure_get_deprecated_caps();
    } else {
        $quant = count($ure_fullCapabilities) - count(ure_getBuiltInWPCaps());
        $deprecatedCaps = array();
    }
    $quantInColumn = (int) $quant / 3;
    $printed_quant = 0;
    foreach ($ure_fullCapabilities as $capability) {
        if ($core) {
            if (!$capability['wp_core']) {
                // show WP built-in capabilities 1st
                continue;
            }
        } else {
            if ($capability['wp_core']) {
                // show plugins and themes added capabilities
                continue;
            }
        }
        if (!$ure_show_deprecated_caps && isset($deprecatedCaps[$capability['inner']])) {
            $hidden_class = 'class="hidden"';
        } else {
            $hidden_class = '';
        }
        if (isset($deprecatedCaps[$capability['inner']])) {
            $labelStyle = 'style="color:#BBBBBB;"';
        } else {
            $labelStyle = '';
        }
        $checked = '';
        $disabled = '';
        if ($for_role) {
            if (isset($ure_roles[$ure_currentRole]['capabilities'][$capability['inner']]) && !empty($ure_roles[$ure_currentRole]['capabilities'][$capability['inner']])) {
                $checked = 'checked="checked"';
            }
        } else {
            if (user_can($ure_userToEdit->ID, $capability['inner'])) {
                $checked = 'checked="checked"';
                if (!isset($ure_userToEdit->caps[$capability['inner']])) {
                    $disabled = 'disabled="disabled"';
                }
            }
        }
        $cap_id = str_replace(' ', URE_SPACE_REPLACER, $capability['inner']);
        echo '<input type="checkbox" name="' . $cap_id . '" id="' . $cap_id . '" value="' . $capability['inner'] . '" ' . $hidden_class . ' ' . $checked . ' ' . $disabled . ' ' . $onclick_for_admin . ' />';
        if (empty($hidden_class)) {
            if ($ure_caps_readable) {
                $capInd = 'human';
                $capIndAlt = 'inner';
            } else {
                $capInd = 'inner';
                $capIndAlt = 'human';
            }
            echo '<label for="' . $cap_id . '" title="' . $capability[$capIndAlt] . '" ' . $labelStyle . ' > ' . $capability[$capInd] . '</label> ' . ure_capability_help_link($capability['inner']) . '<br/>';
            $printed_quant++;
            if ($printed_quant >= $quantInColumn) {
                $printed_quant = 0;
                echo '</td>
					    <td style="vertical-align:top;">';
            }
        }
        // if ('hidden'
    }
}
Esempio n. 3
0
?>
<br /><br />
<hr />
<?php _e('Core capabilities:', 'ure'); ?>
        <table class="form-table" style="clear:none;" cellpadding="0" cellspacing="0">
          <tr>
            <td style="vertical-align:top;">
								<?php ure_show_capabilities( true, true ); ?>
            </td>
						<td>
							<?php ure_toolbar($ure_currentRole, $ure_object, $roleDeleteHTML, $capabilityRemoveHTML);?>
						</td>
          </tr>
       </table>
<?php 
	$quant = count( $ure_fullCapabilities ) - count( ure_getBuiltInWPCaps() );
	if ($quant>0) {
		echo '<hr />';
		_e('Custom capabilities:', 'ure'); 
?>
        <table class="form-table" style="clear:none;" cellpadding="0" cellspacing="0">
          <tr>
            <td style="vertical-align:top;">
								<?php ure_show_capabilities( false, true );	?>
            </td>
						<td></td>
          </tr>
      </table>
<?php
	}  // if ($quant>0)
?>
Esempio n. 4
0
    $ure_apply_to_all = 1;
} else {
    $ure_apply_to_all = 0;
}
if (!isset($ure_roles) || !$ure_roles) {
    // get roles data from database
    $ure_roles = ure_getUserRoles();
    if (!$ure_roles) {
        return;
    }
}
$ure_rolesId = array();
foreach ($ure_roles as $key => $value) {
    $ure_rolesId[] = $key;
}
$built_in_wp_caps = ure_getBuiltInWPCaps();
$ure_fullCapabilities = array();
foreach ($ure_roles as $role) {
    // validate if capabilities is an array
    if (isset($role['capabilities']) && is_array($role['capabilities'])) {
        foreach ($role['capabilities'] as $key => $value) {
            $cap = array();
            $cap['inner'] = $key;
            $cap['human'] = __(ure_ConvertCapsToReadable($key), 'ure');
            if (isset($built_in_wp_caps[$key])) {
                $cap['wp_core'] = true;
            } else {
                $cap['wp_core'] = false;
            }
            if (!isset($ure_fullCapabilities[$key])) {
                $ure_fullCapabilities[$key] = $cap;