How to Fix the Cloudflare WP-Admin Endless Redirect Loop Error with Wordpress

If you are using Cloudflare's free Flexible SSL feature on a Wordpress site and you're experiencing an endless redirect loop when trying to log into /wp-admin, try hardcoding the following into you wp-config.php file:

define('WP_SITEURL', 'https://www.domain.com');
define('WP_HOME', 'https://www.domain.com');
define('FORCE_SSL_ADMIN', true);
define('FORCE_SSL_LOGIN', true);
if( isset($_SERVER['HTTP_CF_VISITOR']) && strpos($_SERVER['HTTP_CF_VISITOR'], 'https') )
$_SERVER['HTTPS']='on';