Skip to content

Instantly share code, notes, and snippets.

@thelevicole
Last active April 12, 2019 14:06
Show Gist options
  • Save thelevicole/24ca85fbbfbeb3245342586820b2073e to your computer and use it in GitHub Desktop.
Save thelevicole/24ca85fbbfbeb3245342586820b2073e to your computer and use it in GitHub Desktop.
Conditional file mods for WordPress admins

Secret conditional file modifcation status for WordPress admins

Copy and paste the contents of this gist into your wp-config.php.

Then access your admin panel with ?wpSuperUser appended to the url. For example: https://example.com/wp-admin/?wpSuperUser This will unlock file modifications for a day allowing you to run core updates, add and remove plugins..etc

<?php
...
/**
* Disable file modifications by default but allow for requests with `?wpSuperUser`
* Set a cookie to expire after a day, allows updates/processes to be ran..etc
*/
if ( !empty( $_COOKIE[ 'wpSuperUser' ] ) || isset( $_GET[ 'wpSuperUser' ] ) ) {
define('DISALLOW_FILE_MODS', false);
$expires = time() + 60 * 60 * 24 * ( 1 ); // Expire in 1 day
setcookie( 'wpSuperUser', true, $expires, '/' );
} else {
define('DISALLOW_FILE_MODS', true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment