Click here to Skip to main content
15,885,890 members
Articles / All Topics
Technical Blog

Fixing protocol errors in WordPress plugins

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
8 Oct 2013GPL3 6.4K  
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)


Written By
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.




Comments and Discussions

 
-- There are no messages in this forum --