HTTPS, SSL, WP_CONTENT_URL
-
Over the past several months I have run into a lot of different problems while trying to use HTTPS with WordPress.
Using the HTTPS for WordPress plugin solves most issues. However, some issues are not resolved. The unresolved issues are generally related to plugins including js files or css files. Examples of this issue include the “Sociable”, “WP-SpamFree”, “NextGEN Gallery” and other plugins.
Every time I see the issue in a plugin, it always occurs when the URL is built using WP_CONTENT_URL. Here are the relevant variable declarations from the above three plugins:
Line 32 of sociable.php (version 3.5.2)
$sociablepluginpath = WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__)).'/';
Line 6798 of wp-spamfree.php (version 2.1.0.9)
$wpsf_plugin_url = WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__));
Line 210 of nggallery.php (version 1.3.6)
define('NGGALLERY_URLPATH', WP_PLUGIN_URL . '/' . plugin_basename( dirname(__FILE__) ) . '/' );
Now, NextGEN uses WP_PLUGIN_URL which is different from WP_CONTENT_URL but is built from WP_CONTENT_URL as shown below.
Line 372 of wp-settings.php (version 2.8.5) defines WP_PLUGIN_URL as:
define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' ); // full url, no trailing slash
Now WP_CONTENT_URL is based on what the user defines as their “siteurl”. That’s why changing your ‘siteurl’ to https generally helps the plugins to work as well as the rest of WordPress. What if you don’t want your entire blog to be https – just a piece of it, say the checkout page (if you use an ecommerce plugin)? A lot of users have issues with this.
I suggest that plugin authors use wp_enqueue script when possible. If not possible I suggest that plugin authors at least check for HTTPS when defining their variables.
Even using something as simple as this code would help many users with their HTTPS problems:
$variablename = (empty($_SERVER['HTTPS'])) ? WP_CONTENT_URL.'mypluginpath' : str_replace("https://", "https://", WP_CONTENT_URL.'mypluginpath');
If you have had problems with https on other plugins feel free to list them.
- The topic ‘HTTPS, SSL, WP_CONTENT_URL’ is closed to new replies.