Wordpress EasyAdmin删除编辑项目的选项

时间:2014-05-15 17:18:15

标签: php wordpress wordpress-theming

我使用的wordpress主题为非管理员的用户提供了EasyAdmin选项,以便他们可以在网站上编辑他们的列表。但是,每个用户角色都有他们可以或不可以更改的列表的特定选项。例如,directory_1directory_2用户角色根本无法修改其列表,但directory_3用户角色具有编辑其列表的完整功能。 我想要完成的是如何将其设置为某些用户角色可以编辑其列表的位置,而其他用户不能编辑?

剪掉了easy-admin.php:

function aitDirCreateRoles() {

global $current_user, $aitThemeOptions;

// directory items capability
$capabilityType = 'ait-dir-item';
$capabilitiesAdmin = array(
    "edit_{$capabilityType}" => true,
    "read_{$capabilityType}" => true,
    "delete_{$capabilityType}" => true,
    "edit_{$capabilityType}s" => true,
    "edit_others_{$capabilityType}s" => true,
    "publish_{$capabilityType}s" => true,
    "read_private_{$capabilityType}s" => true,
    "delete_{$capabilityType}s" => true,
    "delete_private_{$capabilityType}s" => true,
    "delete_published_{$capabilityType}s" => true,
    "delete_others_{$capabilityType}s" => true,
    "edit_private_{$capabilityType}s" => true,
    "edit_published_{$capabilityType}s" => true,
    "assign_dir_category" => true,
    "assign_dir_location" => true
);

// set admin capability
$adminRole = get_role( 'administrator' );
foreach ($capabilitiesAdmin as $key => $value) {
    $adminRole->add_cap( $key );
}

$subscriberRole = get_role( 'subscriber' );
$subscriberRole->add_cap( 'directory_account_update' );

// update user roles from admin
if(isset($_POST['action']) && $_POST['action'] == 'update' && strpos($_SERVER['PHP_SELF'],'options.php') !== false){
    $optionName = $_POST['option_page'];
    if(isset($_POST[$optionName]) && isset($_POST[$optionName]['members'])){

        $prefixName = '';
        $options = $_POST[$optionName]['members'];
        $roles = $GLOBALS['wp_roles']->role_names;

        $capabilitiesDirectory = array(
            "edit_{$capabilityType}s" => true,
            "read_private_{$capabilityType}s" => false,
            "edit_published_{$capabilityType}s" => true,
            "delete_{$capabilityType}s" => true,
            "delete_published_{$capabilityType}s" => true,
            "assign_dir_category" => true,
            "assign_dir_location" => true,
            "read" => true,
            "upload_files" => true,
            "directory_account_update" => true
        );

        if(isset($options['role1Enable'])){
            remove_role( 'directory_1' );
            $caps = $capabilitiesDirectory;
            if(!isset($options['role1Approve'])){
                $caps["publish_{$capabilityType}s"] = true;
            }
            add_role( 'directory_1', $prefixName . $options['role1Name'], $caps);
        } else {
            remove_role( 'directory_1' );
        }

        if(isset($options['role2Enable'])){
            remove_role( 'directory_2' );
            $caps = $capabilitiesDirectory;
            if(!isset($options['role2Approve'])){
                $caps["publish_{$capabilityType}s"] = true;
            }
            add_role( 'directory_2', $prefixName . $options['role2Name'], $caps);
        } else {
            remove_role( 'directory_2' );
        }

        if(isset($options['role3Enable'])){
            remove_role( 'directory_3' );
            $caps = $capabilitiesDirectory;
            if(!isset($options['role3Approve'])){
                $caps["publish_{$capabilityType}s"] = true;
            }
            add_role( 'directory_3', $prefixName . $options['role3Name'], $caps);
        } else {
            remove_role( 'directory_3' );
        }

        if(isset($options['role4Enable'])){
            remove_role( 'directory_4' );
            $caps = $capabilitiesDirectory;
            if(!isset($options['role4Approve'])){
                $caps["publish_{$capabilityType}s"] = true;
            }
            add_role( 'directory_4', $prefixName . $options['role4Name'], $caps);
        } else {
            remove_role( 'directory_4' );
        }

        if(isset($options['role5Enable'])){
            remove_role( 'directory_5' );
            $caps = $capabilitiesDirectory;
            if(!isset($options['role5Approve'])){
                $caps["publish_{$capabilityType}s"] = true;
            }
            add_role( 'directory_5', $prefixName . $options['role5Name'], $caps);
        } else {
            remove_role( 'directory_5' );
        }

    }
}

0 个答案:

没有答案