bz2url – a very simple url compressor for wordpress

Its been over a year since we started bz2.in url compression for inhouse projects at Saturn and is being in use for Asianet India and this blog. Recently for a new project we absolutely needed an integrated url shortner, which finally gave shape to the initial version.
Continue reading “bz2url – a very simple url compressor for wordpress”

WordPress – preview and modify a theme till we are satisfied

Since we at Saturn provide wordpress as a CMS, and have more than a handful of experienced WordPress customizers, and themeres we have handled several challeges related to WordPress. The latest one being that the client was offered a facelift, and they wanted to preview the progress of integration. I searched the plugin repositories and blogs, found a lot of solutions, which include theme switchers, theme preview, and even suggestions to have a local copy. Well with our client, we could not think of a local copy, since the database dump itself was about 320GB and the images and videows was a whopping 1200 GB. Well after reading through the source of get_option, a wave struck me.



function new_theme_preview(){
    if(isset(
$_COOKIE['ShowNewTheme'])){
        return 
'myNewTheme';
    }
    return 
false;
}
 
add_filter('pre_option_current_theme''new_theme_preview'10);
 


I added the above to the end of an active plugin, then created two files newtheme.php and oldtheme.php, containing code to set and remove the cookie. The files were put into the top level folder. Once I am done with the theming, I could remove all these manually.

// newtheme.php
setcookie 'ShowNewTheme''1');
header("Location: ./");
 
//oldtheme.php
setcookie 'ShowNewTheme'false);
header("Location: ./");
 

Posting to wordpress using php cli and xmlrpc

A reader once asked me if I could build a command line tool which takes title from one file, and content from another file to create wordpress post. I tried, which finally gave an outline to this script. I dont think that this is very high fly, but for those whom the xmlrpc is mumbo, this might be somthing worth looking into.
Continue reading “Posting to wordpress using php cli and xmlrpc”

Automatic image sizing with static delivery – WordPress Enhancement

Recently I got fed up trying to convince the operators of a client, for whom we had implemented a wordpress site. The operators, even after we repeatedly asked to upload only relevant sizes for certian positions, were trying to make one size fit for all. Hell, places where thumbnails of 1 to 2K would suffice, were being used up by 30K images, resized by our theme constraints. We were running wordpress on lighttpd.
Continue reading “Automatic image sizing with static delivery – WordPress Enhancement”

JSON feed for WordPress

Pretty simple, really. Adds a new type of feed you can subscribe to. Simply add ?feed=json to anywhere you get a normal feed to get it in JSON form (but with a cutdown version of events).

Version 1.1 added support for JSONP. To get a JSONP response instead of a normal JSON structure, simply add jsonp=callbackName to your query, where callbackName is the name of the function to be wrapped with.

Author: Chris Northwood
Download: WordPress Plugin Repository

Speeding up WordPress home page

After about an year, since we launched Asianet News Portal the home page with all the complications had started to show a dead slow performance, and by using our Query Profiler, I could identify the bottleneck as the number of queries, and wordpress itself was telling the status as 48 queries in 6.344  seconds. Now this was a whopping value, and when the latency of 2 to 3 seconds is added to this, the initial html load would be in 9 seconds. Making the total site complete load in about 53 seconds. One can imagine the agony I was feeling, after all the work I had done to get backlinks, and if users who are visiting the site is just running away without waiting for the site to load, then I better not run the site atall.
Continue reading “Speeding up WordPress home page”

Fun digging into WordPress XML RPC

Once we achieved 20K visits per day at asianetindia.com (maintained by Saturn SPL), we planned to hammer in and our target was 30k in three months. We have achived that view the stats. For this twitter and blog helped a lot. We had added auto blogging, and wordtwit both to the existing asianetindia.com. It means each post when published will be tweeted, as well as a post to blog, which contains the excerpt with a back link to the original.

We wanted to get maximum links back into the blog also, and thought that a track back would be the best method and choose that against auto commenting systems. And a full time tester was doing linking related news and posts from other sites to our blog posts. It started to turn tiring when thought of the volume that was getting posted in a day. At this point, we at saturn started to think of automating the linking drive. The out come is autolinker, which is run using the random cron.
Continue reading “Fun digging into WordPress XML RPC”

Using TagTheNet to generate tags on WordPress

Recently on Kerala News by Asianet, though the wp-simple-tags was there, the posts were not being tagged automatically. And on a detailed check I found it was due to a misconfiguration, and once the same was done properly the tagging started smoothly. But already a set of 8K posts were there with no or unrelated tags mistakes and un awareness of the operators who were posting to the site. Now I wanted these to be tagged properly.
I had already used the word-twit plugin and done some mods to the same, so it was more eaiser for me. Just went through the original code of word-twit and salvaged a small script which is attached here with as download.
require_once( dirname(__FILE__) . '/wp-load.php' );
The code above loads the wordpress system and initializes the wp variables and connects to the database.
global $wpdb;
Makesure we have the database abstraction object from wordpress, to select the posts, and do all the required manipulations on the same.
require_once( ABSPATH 'wp-includes/class-snoopy.php' );
Include the inbuilt snoopy class, to mimic a web browser with the most simplicity.
Continue reading “Using TagTheNet to generate tags on WordPress”

WordPress Super Cache on lighttpd

While trying to speed up Select Articles, I got stuck, torn in between WP Super Cache and lighttpd. Already we at Saturn are using lighttpd on several dedicated servers, and know the potential and benefit of having this over Apache though the flexiblity of having a perdirectory configuration at the programmers choice was a big question. A quick search on the Google landed me to a technical blog, notepad and personal web page by Asterios Katsifodimos.

Trying to get WP Super Cache & WordPress working on my fast lighttpd server, I came into problems, mainly because of lighttpd’s lack of (Apache’s version of) the mod_rewrite module. The static files that were created from the cache were not statically served from wordpress. The problem is that in order to use them, the PHP fcgi was called for each request. So, why would we have to call PHP every time that a file can be completely statically provided by the web server?

Read the rest of his version Installing WP Super Cache with lighttpd

function getIpBehindProxy

We were worried, about all the comments on kerala online, being marked as spam by the akismet plugin. When on detailed examination, we found that the basic problem was that wordpress was logging only the immediate downsteam ip as the remote address, well ours was a bit confusing setup, but to handle the traffic we needed it that way.

A search for wordpress behind reverse proxy, landed me to the wordpress support page. In fact the 5th entry on that page is done by Gopka, who is the lead on this project from Saturn.

We started to correct the remote address by overriding the global variable making slight changes to the wp-config, such that we will not accidentally overwrite the changes while upgrading wordpress. Well the code


if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        
$list explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
        
$_SERVER['REMOTE_ADDR'] = $list[0];
  }


when added to the wp-config, it started to log the first IP, and that would be mostly private IPs if the request was from organisations where internet was shared through proxies or using NAT. The case was same at our office, so we had to find the first public ip from the list of IPs and the code for function getIpBehindProxy was the out come.
Continue reading “function getIpBehindProxy”