{"id":46629,"date":"2026-10-10T17:17:36","date_gmt":"2026-10-10T17:17:36","guid":{"rendered":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/?p=46629"},"modified":"2026-10-10T17:17:36","modified_gmt":"2026-10-10T17:17:36","slug":"disable-theme-plugin-file-editor-wordpress","status":"publish","type":"post","link":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/disable-theme-plugin-file-editor-wordpress\/","title":{"rendered":"Disable the Theme and Plugin File Editor in WordPress"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The theme and plugin file editors in WordPress let any administrator change PHP files from the browser. One typo can take the site down, and a stolen admin password becomes a way to run code on the server. This snippet disables the theme and plugin file editor in WordPress, so the Theme File Editor and Plugin File Editor screens and menu items are gone for every user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The snippet<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\n\/**\n * Disable the Theme File Editor and Plugin File Editor.\n *\/\nif ( ! defined( 'DISALLOW_FILE_EDIT' ) ) {\n\tdefine( 'DISALLOW_FILE_EDIT', true );\n}\n\n\/\/ Safety net: deny the editor capabilities even if the constant was set to false elsewhere.\nadd_filter( 'map_meta_cap', 'dpc_deny_file_editors', 10, 2 );\n\nfunction dpc_deny_file_editors( array $caps, string $cap ): array {\n\tif ( in_array( $cap, array( 'edit_themes', 'edit_plugins', 'edit_files' ), true ) ) {\n\t\treturn array( 'do_not_allow' );\n\t}\n\n\treturn $caps;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">How it works<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>DISALLOW_FILE_EDIT<\/code> is the switch WordPress reads in <code>map_meta_cap()<\/code>. When it is <code>true<\/code>, the <code>edit_themes<\/code>, <code>edit_plugins<\/code> and <code>edit_files<\/code> capabilities map to <code>do_not_allow<\/code> for everyone, and the editor menus and screens disappear.<\/li>\n\n\n<li>The <code>if ( ! defined() )<\/code> guard avoids a &#8220;Constant already defined&#8221; warning when wp-config.php or the host already sets it. The older One-Click Import version called <code>define()<\/code> without the guard.<\/li>\n\n\n<li>The <code>map_meta_cap<\/code> filter is the safety net: if the constant was defined as <code>false<\/code> somewhere else, the filter still denies the three capabilities.<\/li>\n\n\n<li>Installing, activating and updating plugins and themes keep working.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Add it with Scripts Organizer<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/dplugins.com\/downloads\/scripts-organizer\/\">Scripts Organizer<\/a> go to <strong>Code Blocks \u2192 Add New<\/strong> and give the block a name. Set <strong>Trigger location<\/strong> to <strong>Everywhere<\/strong>, tick <strong>PHP<\/strong> under <strong>Script location<\/strong>, paste the code into the PHP editor and publish. Leave <strong>Action\/Hook<\/strong> empty. Everywhere code is loaded while Scripts Organizer itself loads, before WordPress checks any capability, so the constant is in place in time. <strong>Admin only<\/strong> would also hide the screens, but Everywhere keeps the capabilities denied in every kind of request.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The best home for the constant is still wp-config.php, above the &#8220;That&#8217;s all, stop editing!&#8221; line. Use the code block when you can&#8217;t edit wp-config.php.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The same code also works unchanged in a small plugin or an mu-plugin.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For more hardening, see <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/lockdown-admin-backend-to-your-ip\/\">Lockdown Admin Backend to your IP<\/a> and <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wordpress-security-updates-email-alert\/\">WordPress Security Updates Email Alert Without a Plugin<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Gotchas<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Scripts Organizer is a code editor too, and this snippet does not restrict it. Limit administrator accounts to people you trust.<\/li>\n\n\n<li>Disabling the code block, or deactivating Scripts Organizer, brings the file editors back. If that matters, set the constant in wp-config.php, where only someone with file access can remove it.<\/li>\n\n\n<li><code>DISALLOW_FILE_MODS<\/code> goes further and also blocks installing and updating plugins and themes from the dashboard. Use it only when updates come from Git or your host.<\/li>\n\n\n<li>On multisite the editors are already limited to super admins; the snippet removes them for super admins as well.<\/li>\n\n<\/ul>\n\n","protected":false},"excerpt":{"rendered":"<p>Disable the theme and plugin file editor in WordPress with DISALLOW_FILE_EDIT, plus a capability filter that holds even if wp-config says otherwise.<\/p>\n","protected":false},"author":1,"featured_media":46630,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Disable the Theme and Plugin File Editor in WordPress","description":"Disable the theme and plugin file editor in WordPress with DISALLOW_FILE_EDIT, plus a capability filter that holds even if wp-config says otherwise."},"_slim_seo_primary_term_category":0,"_slim_seo_primary_term_post_tag":0,"footnotes":""},"categories":[130,3],"tags":[176,175,166,144],"dpc_library":[204],"class_list":["post-46629","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-security","category-wordpress","tag-capabilities","tag-file-editor","tag-scripts-organizer","tag-security"],"_links":{"self":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46629","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/comments?post=46629"}],"version-history":[{"count":1,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46629\/revisions"}],"predecessor-version":[{"id":46665,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46629\/revisions\/46665"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media\/46630"}],"wp:attachment":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media?parent=46629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/categories?post=46629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/tags?post=46629"},{"taxonomy":"dpc_library","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/dpc_library?post=46629"}],"curies":[{"name":"wp","href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/api.w.org\/{rel}","templated":true}]}}