Admin restrictions on WooCommerce stores

Administration of WordPress websites and WooCommerce stores

Here is a short snippet which disables the ability to edit and update files in the WordPress admin panel, except for spcific username (for example ‘admin7’. It does this by adding a function to the ‘admin_init’ action which checks the current user’s username. If the username does not match ‘admin7’, it sets the constants DISALLOW_FILE_EDIT and DISALLOW_FILE_MODS to true.

    function worg_disable_file_edit_and_update() {  
$user = wp_get_current_user();
if($user->user_login != 'admin7') : 
define( 'DISALLOW_FILE_EDIT', true );
define( 'DISALLOW_FILE_MODS', true );
add_action('admin_init', __NAMESPACE__ . '\\worg_disable_file_edit_and_update');

This snippet could be used in cases where the WordPress administrator wants to restrict the ability to edit and update files to a specific user. This could be used if there are multiple users with access to the WordPress admin panel and the administrator wants to ensure that only one user (in this case ‘admin7’) has the ability to edit and update files.

Hire your codeartist

looking for a development of your own project?

is your agency looking for a partner?