Exemplo n.º 1
0
/**
 * Whether current user has capability or role.
 *
 * @param string $cap Capability or role name.
 * @param array $args Arguments such as Post IDs. (will be passed to PW current_user_can() if applicable)
 * @return bool
 */
function wpaa_user_can($cap, $args = array())
{
    global $wp_roles;
    // exist always true. read always true for logged in users.
    if ('exist' == $cap || 'read' == $cap && is_user_logged_in()) {
        return true;
    }
    // true for role
    if ($wp_roles->is_role($cap)) {
        $can = wpaa_user_can_role($cap);
    } else {
        if (wpaa_is_access_area($cap)) {
            $can = wpaa_user_can_accessarea($cap, $args);
        } else {
            $can = current_user_can($cap, $args);
        }
    }
    return $can;
}
        private static function _edit_fields($column_name, $post_type, $post = null, $first_item_value = -1)
        {
            global $wp_roles;
            if ($column_name == 'view_cap') {
                $view_cap = !is_null($post) ? $post->post_view_cap : false;
                $edit_cap = !is_null($post) ? $post->post_edit_cap : false;
                $comment_cap = !is_null($post) ? $post->post_comment_cap : false;
                $post_type_object = get_post_type_object($post_type);
                $editing_cap = $post_type_object->cap->edit_posts;
                $current_user = wp_get_current_user();
                $roles = $wp_roles->get_names();
                $groups = UndisclosedUserlabel::get_label_array();
                $user_role_caps = wpaa_get_user_role_caps();
                $rolenames = array();
                $edit_rolenames = array();
                foreach ($roles as $role => $rolename) {
                    if (wpaa_user_can_role($role, $user_role_caps)) {
                        $rolenames[$role] = $rolename;
                        if (get_role($role)->has_cap($editing_cap)) {
                            $edit_rolenames[$role] = $rolename;
                        }
                    }
                }
                ?>
<fieldset class="inline-edit-col-access-areas inline-edit-col-left">
				<h3><?php 
                _e('Access', 'wp-access-areas');
                ?>
</h3>
				<div class="inline-edit-col"><?php 
                if (self::can_edit_view_cap($post_type, $post_type_object)) {
                    ?>
<div class="inline-edit-group">
							<label>
								<span class="title"><?php 
                    _e('Read:', 'wp-access-areas');
                    ?>
</span>
								<?php 
                    self::access_area_dropdown($rolenames, $groups, $view_cap, 'post_view_cap', $first_item_value, __('&mdash; No Change &mdash;'));
                    ?>
							</label>
						</div><?php 
                }
                if (self::can_edit_edit_cap()) {
                    ?>
<div class="inline-edit-group">
							<label>
								<span class="title"><?php 
                    _e('Edit:', 'wp-access-areas');
                    ?>
</span>
								<?php 
                    self::access_area_dropdown($edit_rolenames, $groups, $edit_cap, 'post_edit_cap', $first_item_value, __('&mdash; No Change &mdash;'));
                    ?>
							</label>
						</div><?php 
                }
                if (self::can_edit_comment_cap($post_type)) {
                    ?>
<div class="inline-edit-group">
							<label>
								<span class="title"><?php 
                    _e('Comment:', 'wp-access-areas');
                    ?>
</span>
								<?php 
                    self::access_area_dropdown($rolenames, $groups, $comment_cap, 'post_comment_cap', $first_item_value, __('&mdash; No Change &mdash;'));
                    ?>
							</label>
						</div><?php 
                }
                ?>
</div>
			</fieldset><?php 
            }
        }