Skip to content

Instantly share code, notes, and snippets.

@careydayrit
Last active April 27, 2021 02:40
Show Gist options
  • Save careydayrit/3630c213d3727d753367072614ceec8f to your computer and use it in GitHub Desktop.
Save careydayrit/3630c213d3727d753367072614ceec8f to your computer and use it in GitHub Desktop.
Deactivate plugin without logging into wordpress
<?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>
<main class="flex-shrink-0">
<div class="container">
<h3>Deactivate Plugins</h3>
<form method="POST">
<?php foreach($plugins as $idx=> $value){?>
<label><?php echo $value?>
<input type="checkbox" name="remove[]" value="<?php echo $idx;?>" />
<br />
<?php }
// Free result set
$result -> free_result();
}
?>
<input type="submit" value="Apply" />
</form>
</div>
</main>
<footer class="footer mt-auto py-3 bg-light">
<div class="container">
<span class="text-muted">Place sticky footer content here.</span>
</div>
</footer>
<?php
if(!empty($_POST)){
foreach($_POST['remove'] as $i=>$v){
unset($plugins[$v]);
}
$u_plugins= serialize($plugins);
$sql = 'UPDATE '.$wp_prefix.'options SET option_value=\''. $u_plugins.'\' WHERE option_name="active_plugins"';
$mysqli->query($sql);
header('Location: wp-plugin-management.php');
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment