May 01
My Sites: My Blog | My Tech Blog | Follow me on Twitter
----

If you have ever had these errors or just want to be prepared in case they pop up somtime (and they surely will), then read on as I discuss various situations that lead to them and also their solutions.

I generally use desktop clients (mostly blogjet, but also Windows Live Writer and Scribe Fire sometimes) to blog to my WordPress based blogs. Some months ago, I started getting "Http 406: Not Acceptable" error while posting a particular post. Tried posting through the WordPress inbuilt TinyMCE editor, but got the same result. A little bit of research told me that this was because the post contained some words that were considered harmful by the "mod_security" plugin for apache that had been installed by my host to prevent hacking attempts. The quick resolution was to include the following lines in my .htaccess:

CODE:
  1. <ifmodule mod_security.c>
  2. SecFilterEngine Off
  3. SecFilterScanPOST Off
  4. </ifmodule>

Sure enough, I put them in, published the post, and it worked. But since this meant opening up my site to the real hacking attempts, I commented them out and went about my work, occassionally turning them on as and when required.

But, a few days ago, after a server upgrade, the problem reared its head again, and in a more vicious manner. I started getting the dreaded 406 error again, and this time for any post, even a blank post, and through all clients. But this time, TinyMCE was working without issues. A little bit of looking around my site told me that the problem was that my desktop clients were not able to connect to my "x mlrpc.php" file which is responsible for taking care of all the remote api provided by WordPress. Trying to access it through any means provided the 406 error. My site's error log was filled with:

An appropriate representation of the requested resource /x mlrpc.php could not be found on this server.

Now, the xml rpc methods are used not just by WordPress but many other CMS's (like drupal, joomla, etc) and sure enough a quick search resulted in many similar reports for all the platforms. Enabling my previous mod_security options resulted in "503: Server misconfiguration" errors, complicating things further.

On seeing the error logs, I found that the server could not understand the options, and then I discovered that the mod_security had been upgraded to and it wasn't backward compatible with old options. Modifying the options to their latest counterparts also didn't work, as further wading through mod_security manual told me that now, its options cannot be overridden through .htaccess and can only be changed by the web admin.

I found that my host has basically blocked the x mlrpc.php file from being accessed at all instead of using proper rules for blocking only the attacks while allowing valid accesses. This was the problem that a huge number of people are also having and moreover they (like me) are not able to convince their hosts to switch to proper rules.

However, not all hope is lost. I have "fixed" this issue with a workaround for now. It is pretty simple really. Just rename your x mlrpc.php to something else (e.g. myrpc123.php) and also replace all references to it in your CMS with your new file name. You can use sed to automate this task. I used perl however:

CODE:
  1. perl -e 's/x mlrpc.php/myrpc123.php/gi' -p -i *

Now, the 406 errors should be gone. If this worked for you, or you had any issues let me know. Also, if you have any other workarounds/fixes of your own, do drop me a word.

Note: In the above article, please ignore the space between "x" and "mlrpc" as the mod_security rules prevent them from being in content also. Moreover, use some unique name for rpc file.


----
If you liked this post, then you can Subscribe to my feed
Quote of the day: Ralph: Me fail English? That's unpossible.

written by Shantanu Goel \\ tags: , , , , ,

Apr 11
My Sites: My Blog | My Tech Blog | Follow me on Twitter
----

Updated my WordPress plugin shantz-wp-qotd to version 1.2.2 today.

Introduction: Shantz WP QOTD is a plugin to add quotes to your wordpress blog in a few easy clicks. It adds quotes to your posts and your sidebars with a multitude of options for sources and customization.

Changelog:

Version 1.2.2

  • Fixed a bug because of which quotes were blank some times. Thanks to Thom for reporting it.

For more details and download, go to Shantz WordPress QOTD Home Page


----
If you liked this post, then you can Subscribe to my feed
Quote of the day: "Kenny's family is so poor that yesterday, they had to put their cardboard box up for a second mortgage." -- Cartman

written by Shantanu Goel \\ tags: , , , , ,

Apr 07
My Sites: My Blog | My Tech Blog | Follow me on Twitter
----

Situation: You are migrating your WordPress blog from PHP4 to PHP5 (intentionally or being forced to as you web host won’t support PHP4 anymore). Most of the times, this is as simple as adding some simple lines to .htaccess (e.g. AddHandler application/x-httpd-php5 .php ). And you might not notice any issues. But many of you still do. The issues range from weird page layouts, to some controls not working, to some errors popping up here and there, and probably your blog not even displaying. This occurs because even though WordPress is PHP5 compatible, some of the plugins you are using might not be. But even if you ensure that all your plugins are PHP5 compatible, there is still one more problem that I just saw today.

Problem: My host supports both PHP4 and PHP5. I decided to migrate my personal blog to PHP5 today by adding the aforementioned line to my .htaccess. Immediately, my blog disappeared, and in its place, all that was left was a few errors:

[07-Apr-2008 12:11:49] PHP Warning:  flock() expects parameter 1 to be resource, boolean given in /…/wp-cache-phase2.php on line 105
[07-Apr-2008 12:11:49] PHP Warning:  fopen/…/wp-cache-e3ba4b7161eb59d50c5e976a0b66782a.meta) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied in /…/wp-cache-phase2.php on line 240
[07-Apr-2008 12:11:49] PHP Warning:  fputs(): supplied argument is not a valid stream resource in /…/wp-cache-phase2.php on line 241

Note: I’ve deleted the exact file paths above for security reasons.

It gave me an idea that it had something to do with wp-cache. When I tried to open the settings for wp-cache, it again gve error that web server doesn’t have the permissions to write the file wp-cache-config.php, wp_cache_mutex.lock etc.

Continue reading »


----
If you liked this post, then you can Subscribe to my feed
Quote of the day: Ralph: Me fail English? That's unpossible.

written by Shantanu Goel \\ tags: , , , , , , , ,

Apr 07
My Sites: My Blog | My Tech Blog | Follow me on Twitter
----

Many users reported errors while activating the version 1.0.1 of my WordPress plugin shantz-wp-prefix-suffix. I tracked it down to a typo that crept into the release somehow. So, if you are using it, then download the fixed version 1.0.2 from the shantz-wp-prefix-suffix homepage.


----
If you liked this post, then you can Subscribe to my feed
Quote of the day: Grandpa: My Homer is not a communist. He may be a liar, a pig, an idiot, a communist, but he is not a porn star.

written by Shantanu Goel \\ tags: , ,

Apr 06
My Sites: My Blog | My Tech Blog | Follow me on Twitter
----

Some time back I had posted a little hack to fix an issue that users of i3theme have, i.e., their right sidebar drops to below the main content area in IE6. But it wasn’t that good as it took care of only the situation when this phenomena was caused by the tag cloud widget. So, here is a little modification I did to fix the issue more properly.

1. Go to your wp-content/themes/<i3theme> folder and open the style.css file in your favourite text editor.

2. Search for “#sidebar” (without the quotes) until you reach the following code:

CODE:
  1. #sidebar-right,
  2. #sidebar-left {
  3.  width: 210px;
  4.  color: #666666;
  5.  line-height: 160%;
  6. }

3. Now, modify this code to look like:

CODE:
  1. #sidebar-right,
  2. #sidebar-left {
  3.  width: 210px;
  4.  color: #666666;
  5.  line-height: 160%; 
  6.  word-wrap: break-word;
  7. }

4. That’s it. Save your file and you are done.

So what does it do? Basically I just added an attribute “word-wrap: break-word” to the sidebar handling. So, if there is a word that cannot fit in the sidebar width, the word will be broken to continue in the next line and thus the sidebar alignment will remain intact. let me know if you face any issues with this.

Note that this particular word-wrap property is Internet Explorer specific. Firefox (and other browsers) will ignore it, but since the problem with sidebar alignment occurs only with IE, so it will enable IE to display your site properly.


----
If you liked this post, then you can Subscribe to my feed
Quote of the day: Grandpa: My Homer is not a communist. He may be a liar, a pig, an idiot, a communist, but he is not a porn star.

written by Shantanu Goel \\ tags: , , , , , , , , ,

Mar 23
My Sites: My Blog | My Tech Blog | Follow me on Twitter
----

There are many code syntax highlighter plugins available for WordPress (e.g. iG Syntax Highlighter, WP-Syntax, etc) but almost all of them have a problem. They want you to write the code in “HTML editing mode”. If you use any kind of WYSIWYG or visual editors (like built in TinyMCE or offline clients’ similar modes), there is a grave problem. Your code becomes garbled. e.g.:

If you intend to write:

CODE:
  1.  cat abc > /dev/null

It might turn out as:

CODE:
  1. </p>
  2. <p>&nbsp;cat abc &gt; /dev/null
  3. </p><p>

 The issue here is that the code highlighting plugins use the “exact” text entered within the [ code ] (or similar) tags, and since we used the WYSIWYG/visual editors, they add html formatting tags to the code and also convert some special characters into HTML entities (e.g. > into &gt;, < into &lt;, white space into &nbsp;, etc).

The workaround is that you can write the code in html editing mode. But the problem here is that if you happen to switch to the visual mode or edit your post in this mode any time later, the problem will come back which makes editing posts a pain. So, here is a simple hack that will let you write your code in visual/WYSIWYG mode without doing anything special.

Continue reading »


----
If you liked this post, then you can Subscribe to my feed
Quote of the day: Morpheus: Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony.

written by Shantanu Goel \\ tags: , , , , , , , , , , , , ,

Mar 19
My Sites: My Blog | My Tech Blog | Follow me on Twitter
----

Disclaimer: I’m neither a WordPress guru nor a PHP expert. This is what it is, a dirtly little hack, otherwise I’d have called it an “enhancement”

Now onto the main things.

Aim: You would have used wp_list_pages (or plugins like dd-list-subpages, that use it) to display a list of your pages/subpages on a particular page. e.g., I use it on my “Projects” pages hierarchy to list all the relevant projects under a particular heading. Now, the thing is that wp_list_pages gives you a lot of options to display things like dates, page title, page link, etc, but that’s not enough. I need to provide a small description for each page as well, to put things into perspective. Obviously, I don’t expect the visitors to go inside each link to see what it holds in store for them.

The Hack: What you need to do is locate a file called “classes.php” in your wordpress installation. It is usually located at <WordPress Base>/wp-includes.

Now, open the file and find a function called “start_el”. This is a function in the “Walker” class, which is used in WordPress to parse tree-like structures. Here, it used by wp_list_pages to list out all the pages. Now, at the very end of this function (just after the closing brace of if ( !empty($show_date) ) { ), place the following piece of code:


CODE:
  1. $description = get_post_meta($page->ID, "description", true);
  2.             if ($page->ID != $current_page)
  3.             {
  4.                 $output .= "    ";
  5.                 if (!$description)
  6.                 {
  7.                     $description = strip_tags(substr($page->post_content, 0, 250));
  8.                 }
  9.                 $output .= $description;
  10.             }!

What this code does is:

1) Look for a custom field called “description” in your pages. If present, it will show what you wrote there after each of your page in the list generated by wp_list_pages. (To add a custom field to your page, look at the very bottom of your “write” page or “manage” page in the WordPress dashboard.

2) If the “description” field is not present (obviously you might not like to go back and add a custom field to all your pages), it takes the first 250 characters of your page’s content and displays that.

The Hack Is Not Finished Yet: There is just one little thing left to do. As I mentioned, this function is used other times as well (e.g. making your navigation menu). So, you don’t want the description to be appearing always, otherwise it will wreak havoc on your site’s layout. So, there is again a dirty little trick to prevent this.

At the place where you are calling wp_list_pages, modify the call to include the following code before and after the call:

CODE:
  1. update_option('my_wp_list_pages_option', 1);
  2.         $content .= wp_list_pages($your_wp_list_pages_options);
  3.         update_option('my_wp_list_pages_option', 0);

And, modify the previously listed code as well to look like:

CODE:
  1. $my_wp_list_pages_option = get_option('my_wp_list_pages_option');
  2.  
  3.         if ($my_wp_list_pages_option == 1)
  4.         {
  5.             $description = get_post_meta($page->ID, "description", true);
  6.             if ($page->ID != $current_page)
  7.             {
  8.                 $output .= "    ";
  9.                 if (!$description)
  10.                 {
  11.                     $description = strip_tags(substr($page->post_content, 0, 250));
  12.                 }
  13.                 $output .= $description;
  14.             }
  15.         }

What this does now is that it adds an option/variable to WordPress database, which you set to 1 before calling wp_list_pages to tell your code that now its time to display the description, and then restore its state to 0, to prevent the description from being displayed for any other wp_list_pages call.

For your reference, I'm attaching my copy of classes.php here.File Attachment: classes.php.zip (6 KB).
For an example of how it finally looks like, take a look at my “Project” page.

Now It Is Finished: Yes, am not lying. It’s done. All your “Thank You’s” are accepted, and so are your flames, if any .


----
If you liked this post, then you can Subscribe to my feed
Quote of the day: "There's a time and a place for everything, and it's called college." -- Chef

written by Shantanu Goel \\ tags: , , , , , , , , , ,

Mar 15
My Sites: My Blog | My Tech Blog | Follow me on Twitter
----

Just some news on my WordPress plugins front. shantz-wp-qotd has been updated to version 1.2.1 and shantz-wp-prefix-suffix has been updated to 1.0.1. It is just a minor update meant for people still using a WordPress version < 2.1. The update makes the “page exclusion” feature of both the plugins (i.e. the option to prevent the plugins from acting on “pages”) compatible with WP < 2.1 as well.

Go to their respective pages for downloads:

shantz-wp-qotd

shantz-wp-prefix-suffix


----
If you liked this post, then you can Subscribe to my feed
Quote of the day: Homer: [drunk] Look, the thing about my family is there's five of us. Marge, Bart, Girl Bart, the one who doesn't talk, and the fat guy. How I loathe him.

written by Shantanu Goel \\ tags: , , , ,

Mar 01
My Sites: My Blog | My Tech Blog | Follow me on Twitter
----

jeffro2pt0 has a little contest going on his blog, giving out coupons to wpdesigners.com which lets you get atleast 12 WordPress themes for just 5$. Only thing you have to do is give a unique idea that could help improve wordpress. Now, I don’t want anymore themes (actually I’m a cheap-skate who can’t spend even 5$ for a theme, unless one of you decides to get me one ), but I got a few ideas instantly.

I’m going on a week’s vacation with no net connection, hence this sprang to my mind. What if I can “call” my blog? If I can install a VOIP gateway kind of thing on my web server (or maybe use a third party one, like skype?) and give it access to my database. Now, I can just call my blog’s number from any phone in the world and the possibilities are now endless. e.g.:

  • I could moderate comments through a voice mail like system, the blog can read out the comments to me, using text-to-speech, and I can press buttons, or use IVR to moderate them.
  • I could even call in and “dictate” posts to my blog that can be published. Thus we will be saved from writing a lot of future posts before going on vacations (like I’m doing right now )

Can you think of any more uses of this? Or can you think of any other innovative ideas for improving WordPress, or blogging in general? If yes, then let me know. Lets see what ideas those great minds out there can spin out..


----
If you liked this post, then you can Subscribe to my feed
Quote of the day: "When due process fails us, we really do live in a world of terror." - JC Denton

written by Shantanu Goel \\ tags: , , , , , , , , , , , , ,

Feb 29
My Sites: My Blog | My Tech Blog | Follow me on Twitter
----

If you serve any kind of files for download on your WordPress blog(s), one thing you should definitly be looking out for is a download manager plugin. Post attachments are oh-so-2007. Uploading files to your server and hand-posting links everywhere is a pain in the butt. And what about your hunger for statistics?

Well, if you agree with me, then i would like to tell you about two fantastic plugins:

  • Drain Hole: This is a real time saver. Some of the features are:
    • Automatic scanning of directories to generate downloadable files.
    • Simple interface to upload files
    • Categorized downloads
    • SEO urls (no more of those weird links)
    • Automatic hotlink protection
    • Simple integration with SVN repositories
    • Can maintain versions of the files (cool !!)
    • Download urls can be different from their actual path in your server
    • Can even pick files from directories residing out of your www or public_html directory.
    • Superior download security by assigning permissions based on WordPress user roles.
    • Template tags allow you to insert any particular file(s) or list of all files or files in  particular folder on any post, page, sidebar widget
    • Statistics – no. of downloads, IP addresses, referrers, etc
    • Can force files like php, html, txt etc to be downloaded rather than displaying in browser
    • Pretty, can attach icons to files for displaying, different templates can be used for displaying files
    • and…..AJAX

phew, lemme catch my breath here…you can download it from here.

  • WP-Vault: This is the second best plugin I could find in this category. It is not as feature rich as Drain Hole, e.g., it misses SEO URls, hotlink protection, svn integration, versioning, etc, but it does have its own set of interesting features:
    • get files from FTP/HTTP directly without downloading to computer first. (a real time saver)
    • Image galleries from stored images.
    • Supports WordPress’ caching mechanism to reduce load on database.

You can take your own pick out of the two. And yeah, this blog uses Drain Hole, if you must ask.


----
If you liked this post, then you can Subscribe to my feed
Quote of the day: All we really need to survive is one person who truly loves us-Penelope

written by Shantanu Goel \\ tags: , , , , , , , , , , , , , ,