• Resolved jeremysawesome

    (@jeremysawesome)


    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.

Viewing 6 replies - 16 through 21 (of 21 total)
  • Plugins that enqueue scripts do so as the codex and the source code suggests. Unfortunately this means full urls.

    WordPress default scripts, since the location in known, passes relative urls, “/wp-includes/js/jquery/jquery.js”. The solution is for plugins to do the same.

    Instead of https://www.example.com/wp-content/plugins/something/custom.js”, pass “/wp-content/plugins/something/custom.js”.

    This means that plugin authors that use WP_PLUGIN_URL and WP_CONTENT_URL should manually remove “https://www.example.com”

    Also, I believe the functions at https://codex.www.ads-software.com/Determining_Plugin_and_Content_Directories are sensitive to ssl. So using plugins_url() for example will return https:// links.

    Pretty much every function that builds URL’s for WordPress is sensitive to SSL since 3.0.

    I’m not sure what function (if any) is used to build the URL’s for links to other internal posts and pages, but if I can figure it out, I can add an option to WordPress HTTPS to stop WordPress from making all URL’s HTTPS, using a simple filter.

    I’ve proven this by adding a filter to the site site_url function and replaced HTTPS with HTTP; however, the anchor tags are not built with this function (but JavaScript, CSS, etc. do use this function to build their URL’s). If anybody knows what function it is and could tell me, that would be really helpful to a lot of people.

    If not, I’ll eventually figure it out if it’s possible or not. If it is, I’ll add the functionality to my plugin.

    Hey Randy,

    That little code snippet gave me exactly enough information to figure out how to disable that functionality in WordPress 3.0+. Thank you very much!

    I have now released WordPress HTTPS v1.0.

    I believe this will fix your problem. If not, let me know. This functionality has been requested a lot.

    For anyone wondering, the correct way to add scripts and stylesheets with a WordPress plugin is to use the plugins_url function.

    I used it like so in my plugin. It is sensitive to SSL.

    plugins_url('', __FILE__);

    I just realized that plugins_url can only be used that way in WordPress 2.8 or above. I’ve changed my plugin to use this code.

    if ( version_compare( get_bloginfo('version'), '2.8', '>=' ) ) {
     $this->plugin_url = plugins_url('', __FILE__);
    } else {
     $this->plugin_url = WP_PLUGIN_URL . '/' . plugin_basename(dirname(__FILE__));
    }

Viewing 6 replies - 16 through 21 (of 21 total)
  • The topic ‘HTTPS, SSL, WP_CONTENT_URL’ is closed to new replies.