Skip to content

Instantly share code, notes, and snippets.

@careydayrit
Last active November 11, 2020 12:42
Show Gist options
  • Save careydayrit/9b70adeef23d901df41130f88cf2d992 to your computer and use it in GitHub Desktop.
Save careydayrit/9b70adeef23d901df41130f88cf2d992 to your computer and use it in GitHub Desktop.
Disable plugin without login to Admin Panel
<?php
header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
// TODO: read the tabe prefix set on wp_config.php
// replace the prefix based on wp-config.php
$wp_prefix = 'wp_';
// For sites not on pantheon just replace the $_ENV with the appropriate connection information
/* pconnect for newbies */
$mysqli = new mysqli($_ENV['DB_HOST'] . ':' . $_ENV['DB_PORT'], $_ENV['DB_USER'], $_ENV['DB_PASSWORD'], $_ENV['DB_NAME']);
// Check connection
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
// Perform query
if ($result = $mysqli->query('SELECT option_value FROM '.$wp_prefix.'options where option_name="active_plugins"')) {
$row = $result->fetch_row();
$plugins = unserialize($row[0]);
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<title>Emergency Manage Plugin</title>
</head>
<body>
<?php foreach($plugins as $idx=> $value){?>
<label><?php echo $value?>
<input type="checkbox" name="<?php echo $idx;?>" />
<?php }
$u_plugins = array_splice($plugins,0,0);
//print_r($u_plugins);
$u_plugins= serialize($u_plugins);
$sql = 'UPDATE rt_options SET option_value="'. $u_plugins.'" WHERE option_name="active_plugins"';
// echo $sql;
//$mysqli->query($sql);
// Free result set
$result -> free_result();
}
$mysqli -> close();
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment