Created
August 24, 2014 12:40
-
-
Save aristath/f115855ab13d7422bf75 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/* | |
Plugin Name: Salts Randomizer | |
Plugin URI: http://aristeides.com | |
Description: Change salts daily | |
Author: Aristeides Stathopoulos | |
Version: 0.1 | |
Author URI: http://aristeides.com | |
*/ | |
/** | |
* This plugin provides a simple way to automatically change the salts on a daily basis. | |
* It requires you make the following changes in your wp-config.php file: | |
* | |
* 1. Delete the salts from your wp-config.php file. | |
* Your salts should look something like this: | |
define('AUTH_KEY', 'H(NL )[uG;!}C*ffXUI3|]^%uPAHh+TW99Xq+?0lo; t<(pt,HIRhE}w%f$O4@u'); | |
define('SECURE_AUTH_KEY', 'Tq<&r3f%?wJ/NymFf/ZVFD_HSh-,ktsk;=8<yM+tW&6G#0$-+^[?|1yx|H+g)K2|'); | |
define('LOGGED_IN_KEY', 'oC+O+.s:yhH6_vf+jw.!&mX!r>JXZ)I HX-_%w<m;o;0WJ^ct =rEpb$?5X>|+_`'); | |
define('NONCE_KEY', 'Ue-+g1V4N`($[sN$*paCE^bK!IAGiF)!cun+b^52%5lUDl_k8~8(/g;c36=^Ay??'); | |
define('AUTH_SALT', '+96{JTkN,ldj_j/gA +@&m]- _u*$R:!:&djqSD<O-1y-5TB4D~>T:jTD[-K2}DW'); | |
define('SECURE_AUTH_SALT', '&:uO[z- XPTCsd+Lw5CX|_U/-N.AHy$OzZP-)%^rS/xg[}<?!N]$4>FGcNXj?7.h'); | |
define('LOGGED_IN_SALT', 'bh8LJ?--&c^>|?u=c=Q^=hwx&C&hcQpt|J8ao*a1K(7U|M#K;~;/<w xdvRxs]8C'); | |
define('NONCE_SALT', 'VdO]W KoH?XjeF{@)S5XM<e.-xk[}wg1-8+<Jv<nIdtP(YjI=bU9|>=mahk<t~fW'); | |
* | |
* 2. After you delete the salts, add this line in their place: | |
require_once(ABSPATH . 'salts-random-filename.php'); | |
* Of course you can change that to your own, completely random filename. | |
* | |
* For the first time this runs, you should copy the salts you deleted from your wp-config.php file in that file like this: | |
<?php | |
define('AUTH_KEY', 'H(NL )[uG;!}C*ffXUI3|]^%uPAHh+TW99Xq+?0lo; t<(pt,HIRhE}w%f$O4@u'); | |
define('SECURE_AUTH_KEY', 'Tq<&r3f%?wJ/NymFf/ZVFD_HSh-,ktsk;=8<yM+tW&6G#0$-+^[?|1yx|H+g)K2|'); | |
define('LOGGED_IN_KEY', 'oC+O+.s:yhH6_vf+jw.!&mX!r>JXZ)I HX-_%w<m;o;0WJ^ct =rEpb$?5X>|+_`'); | |
define('NONCE_KEY', 'Ue-+g1V4N`($[sN$*paCE^bK!IAGiF)!cun+b^52%5lUDl_k8~8(/g;c36=^Ay??'); | |
define('AUTH_SALT', '+96{JTkN,ldj_j/gA +@&m]- _u*$R:!:&djqSD<O-1y-5TB4D~>T:jTD[-K2}DW'); | |
define('SECURE_AUTH_SALT', '&:uO[z- XPTCsd+Lw5CX|_U/-N.AHy$OzZP-)%^rS/xg[}<?!N]$4>FGcNXj?7.h'); | |
define('LOGGED_IN_SALT', 'bh8LJ?--&c^>|?u=c=Q^=hwx&C&hcQpt|J8ao*a1K(7U|M#K;~;/<w xdvRxs]8C'); | |
define('NONCE_SALT', 'VdO]W KoH?XjeF{@)S5XM<e.-xk[}wg1-8+<Jv<nIdtP(YjI=bU9|>=mahk<t~fW'); | |
* | |
* In other words, DO NOT FORGET TO ADD THE <?php in from of the define lines. | |
*/ | |
/** | |
* The main plugin class | |
*/ | |
class Salts_Randomizer { | |
/** | |
* Class constructor | |
*/ | |
function __construct() { | |
// If the current transients are valid, do not proceed. | |
if ( ! $this->check_transients() ) { | |
add_action( 'get_footer', array( $this, 'update' ) ); | |
} | |
} | |
/** | |
* Update the salts with new values | |
*/ | |
function update() { | |
$filename = ABSPATH . 'salts-random-filename.php'; | |
// Write new salts to disk | |
$this->write_to_file( $filename, $this->get_new_salts() ); | |
// Save the transients | |
$this->save_transients( $this->get_new_salts() ); | |
} | |
/** | |
* Check if the existing salts are valid or expired | |
*/ | |
function check_transients() { | |
$salts = get_transient( 'salts_rand' ); | |
if ( ! $salts ) { | |
return false; | |
} else { | |
return true; | |
} | |
} | |
/** | |
* Save salts in the db | |
*/ | |
function save_transients( $salts = null, $expiration = 86400 ) { | |
// On mulrisites use set_site_transient() instead of set_transient() | |
if ( is_multisite() ) { | |
set_site_transient( 'salts_rand', $salts, $expiration ); | |
} else { | |
set_transient( 'salts_rand', $salts, $expiration ); | |
} | |
} | |
/** | |
* Get new transients from the WordPress API. | |
*/ | |
function get_new_salts() { | |
$new_keys = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' ); | |
return $new_keys; | |
} | |
/** | |
* Write the new salts to disk | |
*/ | |
function write_to_file( $file, $content ) { | |
global $wp_filesystem; | |
$wp_filesystem->put_contents( $file, '<?php ' . $content, FS_CHMOD_FILE ); | |
} | |
} | |
$salts_randomizer = new Salts_Randomizer(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this plugin. I installed and am seeing errors in log file.
[28-May-2016 12:35:41 UTC] PHP Fatal error: Call to a member function put_contents() on a non-object in /home3/redpill/public_html/markmccoy.com/WP2/wp-content/plugins/mu-plugins/randomize-salts.php on line 123
Line 123 reads:
$wp_filesystem->put_contents( $file, '<?php ' . $content, FS_CHMOD_FILE );
$file is defined on line 68 with my custom file name
$filename = ABSPATH . 'salty_hash.php';
That file is located in my WP root directory where wp-config.php is located.
wp-config.php has
require_once(ABSPATH . 'salty_hash.php');
Any ideas?
Thanks!