Click here to Skip to main content
Click here to Skip to main content

Tagged as

Fixing protocol errors in WordPress plugins

, 8 Oct 2013
Rate this:
Please Sign up or sign in to vote.
Fixing protocol errors in WordPress plugins.

I recently started a new job as a full-time WordPress developer managing several websites and the myriad of custom themes, child themes, and plugins. This is a lesson learned from an issue I had with one plugin in particular.

Using Chrome on OS X, I get security warnings that a script wouldn’t load on a particular page. When I looked into it, I found it was because in wp-admin, my site URL is set to http, but that page (and several others) is served from https. Since there’s a mix of protocols, good browsers will block scripts from running across SSL/non-SSL.

The plugin was using get_options('siteurl') to create the path string used to load scripts through wp_register_scripts. Switching to site_url(), which returns a string with the protocol that the page is being rendered on, let's me now safely load the scripts on any page in the site.

Here’s how it ended up looking:

$old_root_url = get_options( 'siteurl' );
$root_url = site_url();

$path_flash = "$root_url/wp-content/plugins/$pluginName/js/swfobject.js";

Hope that helps someone!

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Morgan Estes
Web Developer Golf Tailor LLC
United States United States

I build websites.

I like to build things, especially using WordPress.

I'm happy working in PHP, JS, HTML, CSS, and a bunch of other acronyms, but I'm happiest when I find a way to put the pieces together to create something useful.

You can see more of my work at http://coderbits.com/morganestes.


Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 8 Oct 2013
Article Copyright 2013 by Morgan Estes
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid