Created
February 24, 2017 09:15
-
-
Save dfinnema/ef9ee9f4aaace59c27a55a1d6255c442 to your computer and use it in GitHub Desktop.
Wordpress Salt Updater for ManageWP Snipets (based on https://wordpress.org/plugins/salt-shaker/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$test = new SalterCore(); | |
$test->shuffleSalts(); | |
class SalterCore{ | |
public $salts_array, $new_salts; | |
public function shuffleSalts(){ | |
$this->salts_array = array( | |
"define('AUTH_KEY',", | |
"SECURE_AUTH_KEY", | |
"LOGGED_IN_KEY", | |
"NONCE_KEY", | |
"define('AUTH_SALT',", | |
"SECURE_AUTH_SALT", | |
"LOGGED_IN_SALT", | |
"NONCE_SALT", | |
); | |
$returned_salts = file_get_contents("https://api.wordpress.org/secret-key/1.1/salt/"); | |
$this->new_salts = explode("\n", $returned_salts); | |
return $this->writeSalts($this->salts_array, $this->new_salts); | |
} | |
public function writeSalts($salts_array, $new_salts){ | |
$config_file = ABSPATH . "wp-config.php"; | |
$tmp_config_file = ABSPATH . "wp-config.php.tmp"; | |
if(file_exists($config_file)){ | |
foreach($salts_array as $salt_key => $salt_value){ | |
$readin_config = fopen($config_file, 'r'); | |
$writing_config = fopen($tmp_config_file, 'w'); | |
$replaced = false; | |
while (!feof($readin_config)) { | |
$line = fgets($readin_config); | |
if (stristr($line, $salt_value)) { | |
$line = $new_salts[$salt_key] . "\n"; | |
$replaced = true; | |
} | |
fputs($writing_config, $line); | |
} | |
fclose($readin_config); | |
fclose($writing_config); | |
if ($replaced) | |
{ | |
rename($tmp_config_file, $config_file); | |
} else { | |
unlink($tmp_config_file); | |
} | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment