WYSIWYG editor in your WordPress theme or plugin

No Comments

Prior to WordPress 3.3 adding WYSIWYG editor to a frontend page meant you had almost reinvent the wheel. In WordPress 3.3 wp_editor was introduced which made developer/designer’s life whole lot easier. Now you can add the same editor used when you type up a post can be added anywhere in your theme or plugin (frontend or backend).

I stumbled across this function by accident when I was checking why the WYSIWYG editor was not working on one of my plugins on WordPress 3.3 . You also can allow users to  upload images if the user has necessary capabilities using the editor wp_editor adds.

Read all about it on the WordPress Codex . Hope someone will find it useful.

WordPress How To: Monthly,Yearly and Daily Archives for Custom Post Types

No Comments

For a plugin I was creating I needed Yearly and Monthly archives with my own slug. Even after setting the rewrite rules it was not working. After much debugging and several hours later I finally figured it out. I’ll explain how you could do the same bellow.

Spoiler Alert: For the impatient, it was as simple as removing the old rules that are not setting the post type before adding the new rules :)

I’m going to assume that you have already familiar with Custom Post types. If you are not read http://codex.wordpress.org/Post_Types and then come back. Most important are Step 5 and Step 6. Other steps are typical for any plugin or theme using custom post types.

Step 1: Register the post type
Read more about registering custom post types at

register_post_type( 'my_class',
array(
'public' => true,
...
'has_archive' => true,
)
);

Step 2: Add rewrite tags and permalink structure

$event_structure = '/events/%year%/%monthnum%/%my_class%';
$wp_rewrite->add_rewrite_tag("%my_class%", '(.+?)', "my_class=");
$wp_rewrite->add_permastruct('my_class', $event_structure, false);

Step 3: Add post_type_link and rewrite_rules_array filters

add_filter('rewrite_rules_array', 'my_class_add_rewrite_rules');
add_filter('post_type_link', 'my_class_post_type_link', 10, 3);

Step 4: Return a proper permalink

function my_class_post_type_link($permalink, $post_id, $leavename) {
$post = get_post($post_id);

$rewritecode = array(
'%my_class%',
'%year%',
'%monthnum%'
);

if ($post->post_type == 'my_class' && '' != $permalink) {

$ptype = get_post_type_object($post->post_type);

$start = time();
$end = time();

$meta = get_post_custom($post->ID);
// This is where I store when the class starts
if (isset($meta["my_class_start"]) && isset($meta["my_class_start"][0])) {
$start = strtotime($meta["my_class_start"][0]);
}

$year = date('Y', $start);
$month = date('m', $end);

$rewritereplace = array(
($post->post_name == "")?$post->id:$post->post_name,
$year,
$month,
);
$permalink = str_replace($rewritecode, $rewritereplace, $permalink);
} else {
// if they're not using the fancy permalink option
}

return $permalink;
}

Step 5: Add rewrite rules

function my_class_add_rewrite_rules($rules){
$new_rules = array();

// This is the important bit, unsetting the rules
unset($rules['classes/([0-9]{4})/([0-9]{1,2})/?$']);
unset($rules['classes/([0-9]{4})/?$']);

$new_rules['classes/([0-9]{4})/?$'] = 'index.php?year=$matches[1]&post_type=incsub_event';
$new_rules['classes/([0-9]{4})/([0-9]{1,2})/?$'] = 'index.php?year=$matches[1]&monthnum=$matches[2]&post_type=incsub_event';
$new_rules['classes/([0-9]{4})/([0-9]{2})/(.+?)/?$'] = 'index.php?year=$matches[1]&monthnum=$matches[2]&incsub_event=$matches[3]';

return array_merge($new_rules, $rules);
}

Step 6: Don’t forget to flush

add_action('option_rewrite_rules', 'my_class_check_rewrite_rules');
function my_class_check_rewrite_rules($value) {
global $wp_rewrite;

//prevent an infinite loop
if ( ! post_type_exists( 'incsub_event' ) )
return;

if (!is_array($value))
$value = array();

$array_key = 'events/([0-9]{4})/?$';
if ( !array_key_exists($array_key, $value) ) {
$wp_rewrite->flush_rules();
}
$array_key = 'events/([0-9]{4})/([0-9]{1,2})/?$';
if ( !array_key_exists($array_key, $value) ) {
$wp_rewrite->flush_rules();
}
$array_key = 'events/([0-9]{4})/([0-9]{1,2})/(.+?)/?$';
if ( !array_key_exists($array_key, $value) ) {
$wp_rewrite->flush_rules();
}
}

That’s it. Most important steps are Step 5 and Step 6

Days of the Week

No Comments

I know it’s little late, but I got tired of all the hate towards Rebecca Black because her single is about Friday. I took the liberty to come up with a list of music videos of every single day of the week. Have fun watching and listening to them. All the other artist deserve the hate Rebecca Black got :D

Dialog Axiata APN update for Android mobiles

No Comments

I was annoyed that I had to configure the APN every time I either installed a OS upgrade after a wipe or switched SIMs on my HTC Hero. I went and composed a complete list of APNs for Dialog Axiata. You just need to copy it to your Android based phone and boot into recover mode and flash the zip file. I hope to post in more detail soon, that’s it for now.

dialog-apns-0.1-signed

Blogging from the iPad

No Comments

WordPress for iOS is not very handy to blog, specially if it has lot of text but it’s perfect on iPad. This post is made from the iPad and I’m loving it. May be I should start a separate blog for it :-?

Bottom line is WordPress for iOS is a win on the iPad. Since blogging became so much easier, expect more blog posts :D

Password reuse

No Comments

Unboxing ZTE MF-100

No Comments

I won a ZTE MF-100 courtesy Dialog Axiata at their The Future, Today social media event held last week.See bellow for the unboxing and setting up photos. There is no how to for making it work with Linux or Snow Leopard because it works out of the box with no issues or caveats at all, enjoy :)

PS: Thank you Dialog, you can follow them on Twitter @dialoglk

Samsung ML-1640 on Linux

No Comments

I got my self a shiny new laser printer because the old Lexmark X1110 was getting old and giving little too many paper jams. I went with Samsung ML-1640 mainly because of it’s initial lower price, lower running costs and good reviews online. I had also read that the printer comes with Linux driver, that was one of the first I have seen.

To much to my surprise as soon as I plugged the printer Ubuntu recognized the printer and installed it, with in few seconds without any clicks or key presses the printer was ready for printing. I never bothered testing on Windows 7 but I’m sure I would have had to install drivers (Samsung claims it takes only 4 clicks).

However I ran to some trouble sharing the printer with Snow Leopard as the driver selected by Ubuntu needed to be used as a raw printer queue and I could get around how to set it up on Snow Leopard. Instead I flipped around the setup, I shared the printer as a raw printer queue and used the built in driver on Snow Leopard for the printer. I had to do the same for my notebook as well. Everything was working perfectly, finally :) . In the process I also figured out that Generic GDI driver works as long as the print job fits the printer memory (8 MB), if you send a larger job it will fail with nothing printed (but the printer receives the job).

For anyone wondering, on Linux the driver used is (automatically selected by Ubuntu) is Samsung ML-1640, SpliX V. 2.0.0 , which covers all capabilities of the printer (may be except for toner level).

I’m really happy with the printer, I think it was a very good purchase. I really like the idea the cartridge comes with a handle to push it into place. Then the fact that I can print the demo page by pressing and holding the reset/cancel button on the printer to get the toner level and other printer details. Only thing I miss is fully duplex printing, but with the lower cost I don’t mind working upto the printer to feed the paper when the printer is done printing one side of the pages.

BBC interviews Dom Sagolla, one of the creators of Twitter

No Comments

iKeyword – Free 1.0.1, iKeyword 1.0.2 and a busy week

No Comments

iKeyword – Free, free iPhone App was released on Monday to help you whether it’s worthwhile to purchase the paid iPhone App iKeyword. iKeyword – Free is a huge success, if you haven’t already tried it you should head over to the App Store and download. Available on the App Store

On Thursday (29th July), an update to iKeyword was released enabling users fetch unlimited number of related keywords based on user feedback upping the version to 1.0.2 from 1.0.1 . If the number of related keywords returned was an issue that prevented you from using iKeyword; download to iKeyword 1.0.2 now on the iPhone App Store.

Whole of this week I have been working on an uber cool iPad application which will hopefully be released in August, it’s a biggie. Stay subscribed or follow me on Twitter to be the first to hear when it’s released.

Btw, system administrator appreciation day falls tomorrow; do not forget to throw a party for your SysAdmin, get him/her a gift or just say thanks :)

Older Entries