Archive

Author Archive

jQuery's no-conflict mode: yet another reason why it's the best

July 3rd, 2007 42 comments

It took me a bit to find out why jQuery (now bundled with WordPress) was not working as I expected inside of the WP admin area. The script was being called, but my code like $("#foo") was not working. I really had no clue where to begin, since it still has all those old JS libraries/frameworks being called as well. It was due to Prototype being packaged with it and conflicting with the "$" shortcut.

Long story short, jQuery already planned for library conflicts and has a quick solution. The no-conflict mode allows you to define your own shortcut, and of course it works like a charm.

It's easy to do - just put this line in your code somewhere:

var J = jQuery.noConflict();

Now $("#foo") will be J("#foo") and it will not conflict with any other libraries that may be installed. I hope WP gets rid of all the other stuff and goes with pure jQuery and plugins soon enough though 🙂

Categories: Development, WordPress

Why does WordPress allow empty post titles and bodies on publish?

July 3rd, 2007 4 comments

I have noticed (and also reported this on the WP site) that when a user clicks "Publish" it does not check for empty post titles or empty post bodies. I believe this is a flaw in design. The code is there to check, but it doesn't work right; it allows for empty post bodies or titles for drafts (which is okay, they might not have a title yet) but it should stop the user from being allowed to publish an empty post.

Below is the code I came up with after messing around for hours... it relies on the bundled jQuery in the latest WP 2.x versions. It does client-side checks to alert the user to fix the issue, but there is no graceful way (at least that I could find) to handle this if the user does not have JavaScript or anything enabled. If the server gets an empty title or body, it will empty all the fields out, essentially forcing the post to fail. The user *will* lose their work then (unless their back button works nicely.)

The typical user will typically have JS enabled, and they shouldn't be publishing without a title. However, I am dealing with some inexperienced bloggers - so I want to make sure I have all the bases covered. Once again, the reason this is so ugly is due to the fact that I do not modify the core WP code; everything I do is in plugin fashion (although I did suggest a quick fix in the WP core code in my forum post.) 

Links to my forum post and the bug submission:

Here's the code:

function empty_filter($text) {
   return '';
}

# if any field is empty, forcibly empty the fields so that it will fail post publishing
function check_empty_title() {
   if(isset($_POST['publish']) && $_POST['publish'] == "Publish") {
      if(empty($_POST['post_title']) || empty($_POST['content'])) {
         add_filter('content_save_pre', 'empty_filter');
         add_filter('excerpt_save_pre', 'empty_filter');
         add_filter('title_save_pre', 'empty_filter');
      }
   }
}

add_action("load-post.php", 'check_empty_title', 1);

function check_empty_clientside() {
echo <<<EOF
<script language="javascript" type="text/javascript">
var wpJ = jQuery.noConflict();
wpJ(document).ready(function() {
   wpJ("#post").submit(function(){
      if(wpJ("#title").val() == '') {
         alert('You must put something in the post title!');
         return false;
      } else {
         if(tinyMCE.getContent() == '') {     
            alert('You must put something in the post body!');
            return false;
         }
      }
   });
});
</script>
EOF;
}

add_action('admin_head', 'check_empty_clientside', 1);
Categories: WordPress

Which WordPress plugins do I use?

May 29th, 2007 No comments

I've had the opportunity to work with WP plugin creation quite a bit at work. We've been able to enforce a strict policy on our WP blog of not allowing *any* core WP code to be modified. The main reason for this is that it will make it much easier to upgrade and not break functionality later on.

Due to that, I've wound up creating or hacking up a bunch of custom plugins for work. One includes a complete authentication system override. Basically it traps all login, logout and registration requests and pushes them to custom URLs, and I trap all requests and process user information from cookies our external authentication system has defined. Then I take that information and force-feed it into the WP system, essentually telling it to emulate who I want it to.

That's not a very general-purpose one for any WP installations outside of my company though. However, I have created one that so far seems to be quite useful, and depending on responses, I may package/fix up more.

As of right now, I wind up customizing almost every plugin I use. Currently, all but the Akismet one is either completely written by me, or was taken from another one and hacked up with extra features.

My current plugin list includes:

  • Akismet - because spam sucks.
  • Comment Cleaner - based off "Chunk Urls" I've combined the URL chunking with word wrapping that behaves properly.
  • "Misc Fixes" - a dummy plugin where I dump some personal tweaks like removing all the wptexturize() calls. Possibly some other good stuff, and maybe a testing ground before pulling code into a seperate official plugin.
  • Remove Dashboard Feeds - my first official "public" plugin, a simple and effective way to disable the feeds from loading in the WP admin dashboard. Especially useful for when your server is behind firewalls, but also great if you don't really care about that information 🙂
  • WP Mail Replacement - PHP's mail() function doesn't work as good as I'd like. I created one that uses popen() directly to the sendmail binary, and allows me to do anything I want - custom headers, attachments, etc. However, now that WP 2.2 is bundling phpMailer, this might not be an issue.

It seems like I use a lot more. I guess I felt cool having a handful of custom plugins, but I really only run a couple on my personal site for now. As I mess around with more, I'll be sure to post.

One thing I would like to see is the database functions put into the pluggable functions. Then I could create a MySQLi plugin that could override the core MySQL calls. That'd be a pretty easy way to allow for custom backends; in the meantime, it looks like I am stuck putting in a wp-content/db.php file (I believe that is the way to do it.)

While we're on the subject of plugins, I think I should be clear here. A "plugin" should not require the stock WP code to be altered. That is a patch or a hack. A plugin is something that can be plugged in without any modification of the core code.

Categories: WordPress

A no-hack dashboard removal plugin

May 28th, 2007 31 comments

I don't know why this wasn't discovered (or a better action put in by the WP folks to begin with that could be disabled) but I was able to find a way to disable the feeds from loading on the WordPress admin dashboard without any need for customized index.php files (which would need to be updated/re-uploaded every time WP is updated.)

I'm not sure why this isn't just a stock WP configuration option. It seems enough people have looked for ways around it. My biggest issue was that it requires connectivity directly with each RSS feed, which does not work very well behind our firewall at work. I'll be damned if I hack up some proxy-capable solution too for the feeds that we don't really even look at.

I knew that there had to be a way to mess with the actions being called to disable them from loading the Javascript, or make the fetch_rss() calls return nothing, or make the index-extras.php script return nothing... the easiest and apparently effective way was making a simple action trigger and finding the right order in which it was effective.

In the end, this is all the code that was required:

function remove_dashboard_feeds() {
   remove_action('admin_head', 'index_js');
}

add_action('admin_head', 'remove_dashboard_feeds', 1);

To make a long story short, I give you the "Remove Dashboard Feeds" plugin, located here. Just download, remove the .txt extension, throw it in the plugin directory and activate it. Simple enough. Works on WP 2.2, and probably 2.1. Not sure about earlier versions, but nobody should be running those anyway (keep up with the times as much as you can! Stay secure and optimized!)

Categories: WordPress

Mozy (the backup client): damn close, but still no cigar...

May 7th, 2007 5 comments

Mozy's got what seems to be a nicely integrated Windows client (not sure how good their Mac client is) - their service seems simple enough, and you can't go wrong with two gigs free or unlimited (I've been questioning how much it takes before it becomes "abuse") for an extremely low $4.95/month.

However, this going back to my blog post a while ago about the end all backup solution, it still is missing one key thing. While the transfer is encrypted and the file contents are encrypted (optionally), the file and directory names are not. When I asked support, the response back was "how would you know what the file is then?" - to me, it's simple. You have an encryption key, why can't the filenames be encrypted as well using the same key, and decrypted on demand? I understand this complicates things then (how do you store junky filenames/etc...) - you'd most likely need a customized filesystem or some virtual layer between the two to do the translation. However, that would basically make Mozy the king in my book for Windows and I assume Macs (read: any level of savvy end-user who wants their data backed up.)

I would still be shopping though for one to use to backup my servers. Duplicity still seems like the best, as it will compress, encrypt, and do differential/incremental backups and due to the nature of how it works, will also mask the file contents so only the user can see them. Rsync.net has recently announced funding and support to help pump some life back into the project, which is promising. It needs native Windows support (which may be tricky... it needs a POSIX compliant backend) and proper S3 integration without patches or external libraries and hacks.

Of course, I was having fun developing my own little PHP interface to S3, which if possible I could then wind up creating my own tools; however, do I really trust my own coding for my critical data and extremely large filesizes? Because it's over HTTP, it's tricky (or maybe impossible) to byte-serve the data in PHP without precaching it into memory first... ah well.

Someone needs to create an efficient C-based one that can be compiled in Windows, OS X, and Linux. Any takers? I'll pay...

Categories: Software

What Virgin Mobile doesn't make clear...

April 4th, 2007 No comments

I bought a prepaid Virgin Mobile phone for $25 at 7-11. I thought okay, it's simple: I buy it, I activate it, it's available to use. Wrong.

What they don't tell you about (well, not clearly) is that you must wait four hours after activating the phone to use any services other than simple voice calls. You're not supposed to text, refill your minutes, etc (at least through the phone)

After talking with customer support rep #1, he told me that the reason I wasn't receiving picture messages was due to the fact that my account only had "bonus money" in it and not actual money I paid. So I used the refill I bought to "top-up" - did that fix it? No.

After talking with customer support rep #2, she informed me of the four hour rule - and that was the reason, NOT the different funds in my account. She also informed me that I am required to have a camera phone to receive picture messages even. So I go and pick up a camera phone. After it fails to let me switch it online, I call up customer support rep #3 who does the phone transfer for me. Okay, so now things should work right? No - he informs me that I need to wait four hours again for this new phone to propogate. Being the techie that I am, I find that nonsense - I tried a little while later, most likely within the four hour period. Did it work? No. But it was time for bed.

Today is almost 20 hours into it now. I tried sending and receiving picture messages. Did it work? No. Customer support rep #4 informs me that if you try any of those "advanced" features during that four hour window, you will kill the phone and it will not let you do that again for the life of the phone - did anyone else mention that? No, they just "advise" against it.

So now it appears I may have two phones that are useless for multimedia messaging, and who knows what else. Why don't they have safeguards built in to the system? How hard would it be to simply reject unauthorized items until it is fully propogated? If nothing else, they could at least inform you the phone will be physically dead.

Oh and another suggestion: fire customer rep #1. Now I've got $30 of wasted credit with them because I was told I had to use that to make things work. Blah.

Categories: Consumerism

Bally's Total Fitness should change their name

January 20th, 2007 1 comment

To what you might ask? Something like "14 Hour Fitness" - I'm not joking.

Tonight I got my ass in gear and decided (around 7PM) that I had enough energy to get to the gym, which is the hardest part. Once I'm there I'll exercise, but that motivation to actually drive somewhere to get sweaty to come back home again is a bitch.

Anyway, I drive up to the gym at 7:24 or so. Closed. On a Saturday? The door says 8PM (which still is a bunch of crap) - but they've decided to pack up shop even earlier tonight. I was able to salvage the little time I had left by going over to the next closest location - I got about 20 minutes worth of exercise before it closed.

Why did I join Bally's? For one, my parents are both members. Other than that, everyone I know is with 24 Hour Fitness. Not to mention that (although the name does lie) a lot of locations are actually 24 hours. Which is a bonus for me, considering my messed up schedule. A friend of mine worked out at 2AM the other night. Could I do that if I wanted to? Nope.

I forgot to mention somehow the contract got signed with a three-year clause in it. Which means I'm stuck paying for this crap for another two years and change. I never signup for anything that long, so I'm curious as to why that got past me (perhaps because other people who are pretty good at catching that looked at it too...) - all I know is that I am quite disappointed with my choice.

Categories: Consumerism

MySQLi support for WordPress 2.0.7

January 15th, 2007 5 comments

Yet another patch (actually the same one, but copied for version compliance.)

Patch file:
wordpress-2.0.7-mysqli.patch.txt

Apply with: "patch -p0 < wordpress-2.0.7-mysqli.patch.txt" in the WordPress install directory.

Categories: WordPress

Verizon joins the bandwagon in text messaging fee hikes

January 14th, 2007 No comments

Our cellular networks are growing. The data portions are being upgraded. There is additional capacity out there. So why are text messaging prices being raised by 50%? Three of the big four have raised them now, with T-Mobile being the only company that has not raised the rates yet.

  • Verizon: Just announced, will be $.15 starting March 1, 2007.
  • Cingular/AT&T: $.15 as of January 21, 2007.
  • Sprint: $.15 as of October 1, 2006.
  • T-Mobile: Still $.10. Stay strong guys.

This is crazy to me; if anything, the rates should drop marginally since they have become extremely popular. It will keep people comfortable paying only a fraction less, which in turn will probably spur more messages - ultimately more money for these companies. However, greed will prevail, and I guess smarter people than I have determined this is the best way to make more money. It is an easy way to get people motivated to buy bulk plans, which I assume typically go unused (so they get away with using less capacity for the same price.)

Categories: Consumerism

Say what you want about Best Buy...

January 10th, 2007 No comments

... but they're a big company, and big companies can be useful.

I won't mention the obvious bad points - the stupid salespeople, incompetent techs, people getting arrested for using two-dollar bills...

Instead, I'm going to share my positive story tonight. Best Buy pulled through for me, as I had hoped. Most big companies will price match (especially in the consumer and office electronics markets) and I'm always looking at the weekly ads. Not just to look for a deal, but just to get a general feel for how the prices are rising and falling.

Anyway, this week Fry's had a sale on Seagate 750GB PATA hard drives for $309.99 - not an amazing deal, but I am in need, and I had a gift card to Best Buy, so the timing was right. I took the ad to Best Buy and had them price match that (after the salesperson told me "750GB PATAs don't exist" and I had to correct him...) - on top of that, because at one point or other Best Buy decided to add me to their mailing list, I get monthly coupons for 10-12% off of various things; this one sounded promising. It said only "external hard drives" on it, and I was hoping it wouldn't be an issue. Sure enough, they either did not care or did not know that it wasn't applicable to my item.

Anyway, now I am the proud owner of another 750GB drive, which is good, considering the 400GB in my Linux box is about to die. Total price: $272.79 (original price was $399.99 - a 32% savings.) While most people can't use the coupon since it's mailed to individual people, the Fry's price match is still valid for anyone to use, so if you want a 750GB drive without the drive to the local Fry's, I encourage you to price match it.

Categories: Consumerism, Toys