Why define('FS_METHOD', 'direct'); Exposes Administrator Permissions and How to Restrict It
Setting define('FS_METHOD', 'direct'); in your wp-config.php file is a common requirement when deploying WordPress on systems where FTP access is unavailable or restricted. This constant tells WordPress to use its own PHP functions, specifically the WP_Filesystem_Direct class, to handle file operations like plugin installation and theme updates directly from the server. While this streamlines the update process by removing external dependencies, it fundamentally changes how WordPress handles privilege escalation during these operations.
When you enable direct filesystem access, WordPress relies entirely on the current user's permissions within the PHP environment. If your web server runs as a user with broad system privileges (which is common in many shared hosting or legacy setups), and that user happens to have write access to the wp-content/plugins directory, WordPress will execute these file writes using that user's identity. The critical security implication here is that this method bypasses the standard authentication checks for file writing actions at the OS level during the update process.
This creates a scenario where any logged-in user with administrative capabilities can trigger plugin installations or updates that result in file modifications they might not normally be able to perform via FTP. In your specific case, you have multiple administrators, and enabling direct mode allows all of them to install plugins without a separate password prompt because the underlying PHP process has sufficient permissions to write to the target directories. The system assumes that if a user can log in as an admin, they are trusted enough to execute these high-privilege file operations.
To restrict this capability so that only you can perform updates while others retain their standard administrative rights, you cannot simply disable FS_METHOD. Doing so would revert WordPress to the FTP method, which might not be available on your server or could introduce its own friction. Instead, you must address the root cause: the fact that the web server's execution environment grants write permissions to a user that effectively acts as a "super-admin" for file operations once direct mode is active.
The most robust solution involves configuring WordPress to enforce a password prompt even when using direct filesystem methods. By default, if FS_METHOD is set to direct, WordPress attempts to use the credentials of the web server user or relies on OS-level permissions. To force authentication, you need to ensure that the WP_Filesystem_Direct class requires explicit credentials before attempting any write operations.
You can achieve this by modifying the wp-admin/includes/class-wp-upgrader.php file or by using a custom plugin hook to intercept the filesystem initialization. However, a cleaner approach in many cases is to adjust the server-level permissions so that the web server user (e.g., www-data) does not have write access to the plugins directory, forcing WordPress to fall back to FTP if available, or requiring explicit credentials you control.
If modifying server permissions is not an option, you can implement a custom solution by overriding the filesystem behavior. Create a file named wp-content/mu-plugins/update-credentials.php with the following logic:
<?php
/**
* Enforce password prompt for direct filesystem access
*/
add_filter('filesystem_direct', function($direct) {
// Force credential request if direct mode is active
if ($direct) {
return false;
}
return true;
});
// Alternatively, force FTP even when direct is requested to require credentials
define('FS_METHOD', 'ftpext');
By setting FS_METHOD back to ftpext (or forcing the filesystem request to fail for direct writes), WordPress will trigger the standard credential input form. In this workflow, you can create a dedicated "Update Manager" user account with FTP credentials stored securely in wp-config.php. When other administrators attempt an update, they will be blocked from bypassing the password prompt unless they provide these specific credentials or have their own authorized FTP accounts configured.
The trade-off here is a slight increase in friction for legitimate updates, as every administrator must ensure their FTP credentials are valid and up to date. However, this restores the intended security model where file modification rights are strictly separated from general administrative privileges. If you prefer not to use FTP, consider running WordPress updates via CLI tools like wp plugin install with restricted user capabilities, which offer a more granular control over who can execute these commands on the server side.