Category Archives: WordPress Plugins

20Mar/14

The Plugin Generated xxx Characters of Unexpected Output During Activation

the-plugin-generated-x-characters-of-unexpected-output-during-activation

While developing a custom WordPress plugin I saw this error when activating it. 

The Plugin Generated xxx Characters of Unexpected Output During Activation

I did a little Googling and found that there are a few most common causes:

  1. A white space before or after the PHP opening or closing tags
  2. A file encoded in UTF-8
  3. Another issue when something is called at the wrong time, or a call that cannot be resolved without intervention
  4. Using the WordPress add_option function. Switching to update_option instead can resolve the problem.

In my case it was #1 that blew it up for me.  Who woulda thunk a blank line would be so horrible?  

Anyway, hope this helps someone down the road who is pulling their hair out like I was.

22Nov/13
Https-150x150

HTTP / HTTPS fix for WordPress

***UPDATE***
So, one of those pesky LaneCC blog network users had a problem with a syndicated blog post that included an iframe embedded YouTube video losing the HTTPS today.  I looked into it and found an additional filter to add to the plugin, so we’re up to v1.1.  Woo Hoo!  Anyway, you can still get it on GIT.


If you have a WordPress website hosted on a secure server (HTTPS) and you try to put a YouTube video in a post or page, the video stopped showing up about 3 months ago.  This is because web browsers started to recognize that showing non-secure content (HTTP) on a secure web page makes the secure web page not secure anymore.  It used to be that you would just get a little warning in your browser saying that a page had mixed content and you could continue on at your own risk.  Apparently that wasn’t good enough, so the browsers just started blocking the non-secure content.  Bummer.

HttpsIn my day job at Lane Community College, one of my duties is to manage a blog network built around WordPress MU.  Luckily I’m just the guy that handles updates and things like that.  Some other guy has to field the several hundred potentially irritated people that can’t get videos to show up on their blogs.

So, here’s the tech version of what happened.  WordPress uses something called OEMBEDs.  This allows you to simply copy and paste the URL of a video on the YouTube website into a WordPress page or post and have that video show up.  Rather than having to use shortcodes, or plugins, or some other intermediate step, you just use the address of the movie.  Pretty slick, when it works.  As I mentioned above, it breaks when you’re on a secure server though.  What happens is that WordPress, as of about v3.6, looks at the OEMBED for YouTube and recognizes of you’re trying to embed an HTTPS link.  Then it sends a request to YouTube with the address of the video.  What breaks is when YouTube sends the video back it uses HTTP, even though you requested it using HTTPS.  Stupid.  

So, after that long, but very informative explanation, here’s the fix.  You simply install a plugin that adds a filter to WordPress.  When it sees something coming in with an HTTP address, it rewrites it as HTTPS.  Kind of a brute force way of dealing with a silly problem, but it’s working.

The plugin I wrote isn’t available on wordpress.org, but you can get it here on GIT.  

 

11Jul/13

Require Login For Single WordPress Page

By default, anyone who comes to your WordPress website can see any page on that website.  What if you want your website to be open to everyone, except you really need to have a page or two that only registered, logged in users see?  Example?  A company intranet, a calendar that’s only for family or a contact info page that’s only for family.  Whatever the reason, there are only a few ways to make sure a page isn’t open to the world.

Make the page private

You know what I mean.  When you’re editing your page you look over on the right side just above the Publish/Save button an see a “Visibility” option.  You can make that private and the page is hidden from the public, but it’s also hidden from all other registered users.  When set to private a page also doesn’t show up in the main menus or anywhere else.  It’s basically hidden from everyone from the one who made it private.

Password protect the page

Under that same “Visibility” section you can also choose “Password protected”.  This is good.  The page shows up in the menus and all that, but this option asks for a password for this particular page.  Basically, you set a password for this page and then you have to share that password with anyone you want have access to the page.  That’s not quite what I’m after.

Create a new page template

So, to recap, I wanted a page that shows up in the menus just like any other page but whose content can only be seen by users who have an account on the website and have logged in.  For all others, I want the page content hidden.  Here’s what I came up with because I couldn’t find a plugin that accomplished this without annoying upgrade messages or adding a lot of bloat for no reason.

  1. Create a new page template by making a copy of your theme’s existing page.php template.  I named mine “page_logged_in.php”.
  2. Once you have your page you need to edit the file in whatever editor you like.  I use Dreamweaver, but any text editor will work just as well.  The first bit of code you need to add names the template so you can find it later.  (This is what you’ll select in the WordPress admin when creating your new page.)  Just add the following code to the very top of the code.  There will most likely be something similar already there.  If so, just replace it.
  3. Now you need to add a little code to see if the user is logged in.  This is pretty easy.  WordPress has hooks built in for this.  The following can be added directly below the Template Name code above, also at the top of the page before any of the standard WordPress stuff.

     

  4. Now, go to the very bottom of the page and add the following code.  This will call wp_die() to halt WordPress and display a notice to the visitor saying they need to log in to view the page.

     This little snippet does a couple things.  If it runs (if the user isn’t logged in) then it halts the page and displays a message that says “To view this page you must first log in.”  The words “log in” are a link created by wp_login_url() which is another WordPress hook.  You may notice get_permalink() embedded in wp_login_url().  What this does is gets the address of the page you’re on so that when the user clicks the link to log in, they come back to your password protected page once they log in.  You can forward them pretty much anywhere you want, but I like to bring people back to where they started to minimize confusion.

  5.  

    Now just save the page template and upload it to your web server where your template files are.  Hopefully you simply duplicated page.php where it already lived, so this is a no brainer.

  6. Next, go to WordPress and create a new page.  Under “Page template”, select the new page template we just created.

  7. Save your new page and that’s all there is to it. That page will now appear just like any other page in your menus, but when a user who is not logged in tries to visit it, they will receive the notice you included above.

Hope this helps.  I looked for a way to do this for about a half a day.  This seems to be a simply way to go about it.

 

07Jun/13

WPMU LDAP plugin fixes

So, one of the little projects I’ve been asked to help with at Lane is to move a number of WordPress websites from an old WordPress Multi-User installation to a fancy new server with a WordPress Network (basically the same thing, just called a network since 3.something).  Anyway, they wanted to make it really slick, so the network admin set up a plugin to authenticate WordPress users against the school’s LDAP server.  In other words, each person (student, staff, faculty…) has a master user name and password for all things having to do with Lane.  Rather than have WordPress outside this, we use the WPMU LDAP plugin to allow users to log into their WordPress sites using their Lane credentials.  Pretty cool.

Couple issues came up though.  The servers at Lane are really tied down so they stay squeaky clean.  Little things that developers often don’t worry about display errors here.  What that does is just makes you, as a developer, really consider what you’re doing with variables.  Here’s what I saw…

Anyway, the WPMU LDAP plugin had a couple minor issues like using deprecated WordPress functions.  If you have found this post because you’re having the same problem, you can download the fixed plugin here.

Please remember that this is for wpmuldap_4.0.2, so check the plugin page on WordPress’s website to see if there isn’t an updated version of the plugin.  I’m about 5 minutes away from contacting the developer to see if he would like to fork my fixes.

13Oct/12

Herbert Lumber – Riddle Oregon

Herbert Lumber had recently lost their website to a server crash.  Scary.  Especially since their host didn’t have a backup.  When I talked to them they were trying to figure out how to get a website back up that they could back up and maintain themselves.  Hmmmm.  What do I have that would work for that?  Yep.  WordPress.

Herbert Lumber Company

It came out pretty well.  They had some of the original photos that they had used on the original site and even some of the content from the pages.  I was able to get a custom WordPress theme set up for them in a couple days and moved all their photos and content over in a few hours.  Now they have a site they can maintain, update and, most importantly, back up on their own.

Unfortunately, Herbert Lumber wasn’t the first client I had talked to that week who had lost their website to a server crash with no backups.  I decided it wouldn’t be a bad idea to have a way to back up a full WordPress installation with a single click from the Dashboard in WordPress.  I wrote a plugin that is available from WordPress that makes a backup of your entire database as well as your entire web root folder.  That means that if you have information on your website that’s not in WordPress, my plugin backs that up too.  Pretty cool, really.  One click makes the backup file, then shows you a link to it so you can download it to your local computer.  Then you just delete the backup file from the server and you’re good to go.  You can run the backup as often as you like.

If you have lost your website, or you’re not happy with the one you have, give me a call.  I’m sure I can help you put something together that will fit your needs, look great and be under budget.

04Oct/11

Total Archive

This is my first plugin. Pretty simple really. I needed something that would allow one of my clients to create an archive of their whole WP site and database, then download it so it didn’t take up a bunch of space on my server.

A few things to keep in mind. I wrote this for my server. Your mileage may vary. I’m running a LAMP server with all latest stable releases (PHP 5.3+, MySQL 5+, Apache 2+) and gzip installed. That may or may not be important. I’m no server guy. All I know for certain is it works with that configuration. I suspect that it will run on most any LAMP setup, but I can’t guarantee it.

One nice thing… The file that is created is named with the site title, date and time of creation and the WP version it’s running. If there’s a server crash, or your web guy dies, you know exactly what you have to do to get back up and running quickly.

If you use it and appreciate it, please throw me a bone. :)