JSON and Wordpress

If you want to encode/decode JSON within/using wordpress, you can take a look at

/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php

This file has Moxiecode_JSON class which can do that for you.
(more…)

Back in USA

Hi Everyone. I’m back in the business!

I decided I will write about my trip the same day I was landed in USA but I was caught up checking 1,000 emails and work load.

It’s always great going back home and meeting your people. I enjoyed a lot this time in India. Hanging out with friends, family regroup, my grandmother and a lot! This year I relaxed a bit as well and some days were so busy. Kite Fastival, Uttarayana or Makarsakranti was too good. I fly kites after 2 years.
(more…)

Wordpress: Automatically adjust for daylight saving time

I have been googling for this and (again) I had to come up with my own solution.

function my_set_gmt_offset($offset) {
        global $wpdb;

        /* Wordpress default sets to UTC timezone
        in wp-settings.php.
        you can change this line to whatever your timezone is.
        I set it to my timezone (NY)
        More: http://www.php.net/manual/en/timezones.php
        */

        if(function_exists('date_default_timezone_set'))
	        date_default_timezone_set('America/New_York');

	$timezone = date("T");

        /* Now we have your local timezone stored in $timezone
        so lets restore wordpress setting as in wp-settings.php */

        if ( function_exists('date_default_timezone_set') )
	       date_default_timezone_set('UTC');

	$current_offset = $offset;

	if($timezone == 'EDT') {
		$offset = '-4';
	}
	else if($timezone == 'EST') {
		$offset = '-5';
	}

	if($offset != $current_offset) {
		/* update offset in database if new offset is different.
		   Do not use update_option since it will call
                   this filter again and cause infinite loop.
		 */
		$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->options
		SET option_value = %s WHERE
		option_name = %s", $offset, 'gmt_offset' ) );

		/* let wordpress regenerate cache from database */
		wp_cache_set('gmt_offset', 'checkthedatabaseplease', 'options');
	}

	return $offset;
}

add_filter('option_gmt_offset', 'my_set_gmt_offset');

Share your feedback via comments.

Comments Pagination – Wordpress – Bug Fixed!

Actually, I did not create a plugin but I wrote a code snippet that did this job for me.

Add these lines to comments.php in your active theme folder.

$comments_per_page = 5;
global $post;
$total = $post->comment_count;
if($total > 0) {
$apage=isset($_GET['apage']) ? intval($_GET['apage']) : 1;
$comments=array_slice($comments, intval(($apage-1)*$comments_per_page),intval($comments_per_page));
}

Insert this code right after if ($comments) statement

$commentCounter = (($apage-1)*$comments_per_page);
$from_page = $commentCounter+1;
if($apage == 1) {
$to_page = $comments_per_page;
if($total < $to_page) {
$to_page = $total;
}
}
else {
$to_page = $from_page + $comments_per_page - 1;
if($to_page > $total) {
$to_page = $total;
}
}

Insert this line where you want page links to appear in comments.php.

<?php echo paginate_links( array(
'base' => add_query_arg( 'apage', '%#%#comments' ),
'format' => '',
'total' => ceil($total / intval($comments_per_page)),
'current' => $apage
));

I think this is it. It should work. Give it a try and share your feedback via comments.

Flickr photos in post using shortcode

Shortcodes are awesome! This time I am showing photos from my flickr account to wordpress post.

Content from X'Mas in NY