最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

capabilities - Create sub-administrator role that can do everything except use or see the code editor

programmeradmin1浏览0评论

I am doing the code work for a website that someone else will be managing. I'm worried that just telling them not to use the code editor for appearance or plugins won't be enough to stop them from doing so.

I've tried the standard WordPress add_role( $role, $title, $capability ) but I can't figure out what combination of terms will allow them to edit pages, posts, post types, add or remove plugins, add and remove users, AND edit the WordPress customizer. I also want to make sure this user role can't delete users with the administrator role.

This didn't do the job:

add_role( 'sub_admin_role', 'Sub-Admin', array( 'level_7' => true ) );

I am doing the code work for a website that someone else will be managing. I'm worried that just telling them not to use the code editor for appearance or plugins won't be enough to stop them from doing so.

I've tried the standard WordPress add_role( $role, $title, $capability ) but I can't figure out what combination of terms will allow them to edit pages, posts, post types, add or remove plugins, add and remove users, AND edit the WordPress customizer. I also want to make sure this user role can't delete users with the administrator role.

This didn't do the job:

add_role( 'sub_admin_role', 'Sub-Admin', array( 'level_7' => true ) );
Share Improve this question edited Apr 22, 2017 at 15:09 Nathan Johnson 6,5286 gold badges30 silver badges49 bronze badges asked Apr 22, 2017 at 6:15 Justin BarrettJustin Barrett 11 bronze badge 1
  • if it is their site, it is not up to you to tell them what to do with it and how to use it – Mark Kaplun Commented Apr 22, 2017 at 6:50
Add a comment  | 

2 Answers 2

Reset to default 1

Use this plugin

https://wordpress/plugins/advanced-access-manager/

This plugin is all you need to manage access to your website frontend and backend for any user, role or visitors.

Activate the plugin. Navigate to Capabilities and remove following two capabilities for your desired role.

edit_themes edit_plugins

Your code isn't working because WordPress deprecated user levels in version 3.0 (June 2010).

What you want to do is create a plugin that upon activation, creates a new role for the owner of the site that is a clone of the administrator role, but cannot edit plugin or theme files. Those capabilities are edit_plugins and edit_themes respectively.

Then, upon deactivation, you want to reassign the owners into the administrator role. This way, they can fully regain control of their website by simply deactivating the plugin.

/**
 * Plugin Name: WPSE 264483
 */

//* On activation, create an owner role that can do everything but edit themes/plugins
register_activation_hook( __FILE__, 'wpse_264483_activation' );
function wpse_264483_activation() {
  $administrator = get_role( 'administrator' );
  $owner = clone( $administrator );
  unset( $owner->capabilities[ 'edit_plugins' ] );
  unset( $owner->capabilities[ 'edit_themes' ] );
  add_role( 'owner', 'Owner', $owner->capabilities );
}
//* On deactivation, re-assign all owners to administrators and remove owner role
register_deactivation_hook( __FILE__, 'wpse_264483_activation' );
function wpse_264483_deactivation() {
  $owners = get_users( [
    'role' = 'owner',
  ] );
  foreach( $owners as $owner ) {
    $owner->add_role( 'administrator' );
    $owner->remove_role( 'owner' );
  }
  remove_role( 'owner' );
}

I've enabled a similar plugin for clients upon request, but I think it's a bad idea to do so without their full knowledge and consent. It is their website after all.

发布评论

评论列表(0)

  1. 暂无评论
ok 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>