WPoet Tip: Custom meta goes blank for custom post type

Custom post types is one of the important and useful feature wordpress have. But I found something strange when I saved custom meta in wordpress admin it went blank after some time, so I checked ajax requests in firefox firebug and found autosave works once I finished my writing in editor and left that page as its. Then searched for the solution and found we need to add a small condition which will restrict autosave to work in custom meta data. Below is the example for how it works…

WordPress api have a hook save_post which we generaly use to save custom meta

add_action('save_post', 'save_details');
function save_details(){
global $post;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return;
if($post->post_type == "mypostype")
{
 update_post_meta($post->ID, 'mypostdata', $_POST['mypostdata']);
}
}

Basically important is to add this condition

if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return;

By adding above condition it return ajax request before updating custom data, so it save me and made custom post type more useful.

Code snipped: Image uploading inside your plugin using wordpress file uploader

I was recently working on a wordpress plugin and need a very small image upload feature just to upload company logo. I was thinking to use the original wordpress file uploader, as it is really very cool and easy to use as well. So after checking few code snipped’s I found the below solution:

Here is the html code for browse button,

<input id="company_logo" type="text" name="company_logo" size="36" />
<input id="upload_button" type="button" value="Upload Image" />

You are required to add these javascript libraries to achieve the lightbox effect and uploader screen

add_action('init', 'call_init');
function call_init()
{
wp_enqueue_script("jquery");
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_enqueue_style('thickbox');
}

and now the actual javascript code, which will do the magic

jQuery('#upload_image_button').click(function() {
formfield = jQuery('#company_logo').attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});

window.send_to_editor = function(html) {
imgurl = jQuery('img',html).attr('src');
jQuery('#company_logo').val(imgurl);
tb_remove();
}

Above code will open a thikbox and allow user to upload image or select from the uploaded one like one we can while adding thumnails or post images on post page. Once image gets uploaded and user presses “insert into post”, the “send to editor” function gets activated and it will copy the image url to input box you had created in the html.

This will look exactly like wordpress image uploader screen.

So upload functionality done here, but what I required was to get the image id or say attachment id once image uploaded successfully and url comes in input box, and for that there is a hook in the wordpress api which we can use while user click “insert into post” button, it is “image_send_to_editor”

add_filter('image_send_to_editor', 'image_to_editor', 20, 8);

“image_send_to_editor” hook get’s called in the background when user press ‘insert into post’ button and provides various parameter, like html, attachment id, caption of the image, title of the image, alignment of the image, url, size and alt tag of the image.
As I only need attachment id from that function to save in db and latter can use it for thumbnail generation, so I just updated a option in the database to save it.

function image_to_editor($html, $id, $caption, $title, $align, $url, $size, $alt)
{
update_option('company_logo_id', $id);
return $html;
}

Hope this will help in image upload features of wordpress plugins. Feedback and questions are welcome here.

WordPress plugins released and got popular in 2010

We already gave adieu to year 2010 and celebrated 2011 with full joy and new hopes. Within the same flow when I look back and counted my learnings of 2010 from my work , I got WordPress in the first position.

Year 2010 gave me lots of opportunity to work in WordPress. I developed few plugins while working on client’s project and updated some existing one for my own use. So I thought lets give farewell to year 2010 by writing a post on plugins only.  So here I am listing some of the plugins which were released in 2010 and got popular (based on the download stats from wordpress.org)

  1. Wickett Twitter Widget : Wickett twitter widget is a very simple widget which show latest tweets from you twitter timeline, you just need to give a valid twitter handle, with this you can set how many tweets you want to show on the your blog .
  2. Share and Follow: Share and follow is a full social plugin which gives you option to add any social icon in your blog like facebook, twitter, linkedin, reddit, stumbler and many more. Not only this, it provides many ways and styles to match your blog’s theme.
  3. Exploit Scanner : Exploit scanner is really awesome plugin which search for suspicious data in your website and list it down for admin to take action. It searches data in your posts and comments database which is considered to be an easily accessible place in your website.
  4. Disable WordPress Plugin Updates: This plugin is really useful for  those users who gets annoyed by updates that comes for the plugins. This pugin disable all the updates that comes for any plugin in your wordpress site.
  5. Facebook Members: Facebook members is a plugin which shows list of members who already liked your site’s facebook page. New users may get attracted by this list on your website and simply like facebook page from the website itself.

While writing this post I also observed that year 2010 was a full social year, as not only people connected through various social medium but developed so many apps, plugins and addons to do the same. 2010 was wonderful social year :)

wpSimpleBackup : a simple wordpress plugin to take backups.

Search engine friendly URL for WordPress plugin

While working on one of my client’s plugin I needed to provide search engine friendly url’s for some custom functionality that was needed and existing plugin was not supporting such urls

       www.example.com/?param1=var1&param2=var2&param3=var3

but for search engine freindly url’s I want it to be like

      www.example.com/var1/var2/var3

So here I am sharing small code snippet which works perfectly for my plguin and showing nice url’s.

We need to update the theme function.php file, just add the below code in function.php file and modify variables according to your need.

<?php
add_filter('rewrite_rules_array','wp_insertRewriteRules');
add_filter('query_vars','wp_insertQueryVars');
add_filter('init','flushRules');

// Remember to flush_rules() when adding rules
function flushRules()
{
  global $wp_rewrite;
  $wp_rewrite->flush_rules();
}

// Adding a new rule
function wp_insertRewriteRules($rules)
{
  $newrules = array();
  $newrules['(mytestpage)/([a-zA-Z0-9_\-]*)/([a-zA-Z0-9_\-]*)$'] =
'index.php?pagename=$matches[1]&var1=$matches[2]&var2=$matches[3]';
  $allrules = $newrules + $rules;
  return $allrules;
}

// Adding the variables  so that WP recognizes it
function wp_insertQueryVars($vars)
{
 array_push($vars, 'id');
 array_push($vars, 'var1');
 array_push($vars, 'var2');
 return $vars;
}
?>

To access these variables from plugin file use following code:

 $var1 = $wp_query->query_vars['var1'];
 $var2 = $wp_query->query_vars['var2'];

Now this will solve your plugins search engine friendly issues.

how to parse a shortcode when page is created or updated

Shortcodes in wordpress are generally use to show some cool things with very less efforts, it may be gallery, a poll or map, generally shortcode get parsed when post/page is viewed. But few days back I was working on the project where I had to parse a shortcode when post/page is created or updated, after checking some shortcode functions, I came up with solution to parse it by using do_shortcode, which will basically parse the code on the moment it get called

I had used it with pre_post_update hook and here is the example:

add_action('pre_post_update', 'parse_my_shortcode');

function parse_my_shortcode( $postid )
{
$post = get_post( $postid );
$content = $post->post_content;
do_shortcode( $content );
}

And it works really amazing!!!

HTML5 Video Player Plugin for WordPress

wp-video-js is wordpress plugin which enables post/page embed with HTML5 video player tag with the use of shortcode.
Shortcode is used to embed HTML5 video player in the content area of post:

[html5video width= "600" height = "300" splash = "http://example.com/splash.png"
src_mp4 = "http://example.com/video.mp4"
src_webm = "http://example.com/video.webm"
src_ogg = "http://example.com/video.ogg" ]

Here are list of parameters that can be set with shortcode:

width => To set the width of video screen
height => To set the height of video screen
splash => To set the splash screen of the video
src_mp4 => MP4 source of the video
src_webm => WEBM source of the video
src_ogg => OGG source of the video

Download link:  Download wordpress HTML5 Video Player plugin (492)

Simple backup plugin for your wordpress blog

Backup is always required for any valuable items we have and on the web our blog is our most valuable identity, so why not take its back and secure all your posts, plugins, themes etc, so that if something goes wrong you should not have to worry.

Recently we have released our simple backup plugin named wpSimpleBackup, which will take backup to cloud files, Amazon S3 or FTP to other server.

What wpSimpleBackup can do? wpSimpleBackup take the full back of your wordpress blog including database, plugins, themes, uploads and save it to your chosen option among rackspace cloud files, Amazon S3 or FTP.

How to install and use? Installing this plugin  is the  same process as  any other wordpress plugins  requires,  you need to copy the wpsimplebackup directory to your wordpress plugins directory and activate it from the admin panel.

Plugin will give you options to chose backup storage among three options, and then need to do the service setting for the chosen storage. You then need to give a container/folder name where it’s going to save the backups. Name of the zip file to identify your backup files. And most important you can do scheduling, take backup daily, weekly and monthly or if you wish you can take backup manually also. An another good feature is you can restrict your backup up to some numbers like last 5 backups or 3 etc. Then save the setting and you are done.

How your backup’s will look?

You can view all your backups from admin panel itself and have facility to delete it or restore it from there only. So this will also going to help you if you simply need to do migration.

I will simply list the amazing features once again

  • Backup of whole blog including database, wp-config.php, plugins, themes and other files in wp-content folder.
  • Three options of storage rackspace cloud files, Amazon S3 and FTP
  • Scheduling of backup with options of daily, weekly or monthly other then this one can take manual backup anytime.
  • You can restrict number of backup files you want.
  • Can view backups from admin panel, delete backup and restore it from panel itself.
  • It is simple, easy and fast.
  • Best wordpress blog migration tool I ever found and now its your turn.

Where can you get this plugin? You can checkout this wpSimpleBackup

Update: This plugin is pulled down, try following plugins as alternatives
BackUpWordPress
backupbuddy

Debugging log plugin for wordpress

Few days back I was working on a live wordpress site and need to debug some code, as it was live I can’t add some echo’s and exit so I added email code and then check the emails continuesly, then I reliaze I need a logging mechanism and I made this simple logging plugin, which will log my debugging code and its easy to compare anything there rather then in emails.

Call debug log plugin create a log file date wise in the wp-content/logs directory, you just need to add this plugin, activate it and call

$content = “This content needs to be logged ”;

do_action(‘calldebuglog’, $content);

where $content is any debug code you want to check in the log file, and “calldebuglog” is hook which will call the required function.

Download link :  Debugging log plugin for wordpress (536)

Let me know your views and thoughts on this.

wpSimpleBackup : a simple wordpress plugin to take backups.

Links

phpcamp pune 2011: A gathering of php enthusiast

Twitter

  • now what will happen to our :(, congratulations @adii n team RT The WP App Store is now live!
    http://t.co/GX4fVbAL
    2012/05/15 22:29
  • Without Internet at office for whole day, thanks to BSNL.
    2012/05/14 23:20
  • Back after luch for #punebloggersmeet
    2012/05/05 14:42
  • New faces, good stories from various bloggers at #punebloggersmeet , yes intro is still happening
    2012/05/05 13:02
  • So @sandygautam is here.. And he looks different from his pic :) #punebloggersmeet
    2012/05/05 12:45

Pages

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 Buy Prednisolone Pharmacy Prednisolone Best Price Buy Erythromycin In The Us No Prescription Erythromycin Online Pharmacy Sydney Australia Maxalt Fast Canadian Pharmacy Cheap Buy Vasotec Online Cheap Prevacid No Prescription Uk Prevacid Mail Order Diflucan For Sale Canada No Prescription Drug Store Cheap Phenergan In Australia Phenergan Mail Order No Prescription Meds Viagra Shipped From Canada Online Pharmacy Solutions Buy Professional Plasma Tooth Whitening Kit Online Buy Aricept Cheap Online Free Viagra Samples Buy Premature Ejaculation Cure In Edmonton Canada Discount Prices Buying Wellbutrin SR In Toronto Canada Best Prices Buy Cialis Super Active Online Cheap Free Viagra Samples Canadian Pharmacy Meds Buy Lumigan Eye Drops Online Cheap Nitroglycerin Online No Prescription Discount Prices Sublingual Viagra No Prescription Uk Sublingual Viagra Mail Order Online Pharmacy Germany Wellbutrin Online Cheap Yasmin Online Without Prescription In Canada Fast Online Pharmacy In The Uk Buy Neurontin Online Cheapest Male Enhancement Oil Canada Free Viagra Sample Pills Fucidin Edmonton Canada No Prescription Fucidin How To Get Cefixime Canada Order Online Here Brand Amoxil Uk Pharmacy Brand Amoxil Shipped From Canada Buy Quick Melt Melatonin Online Nz Quick Melt Melatonin Mail Order Tretinoin Cream Price Per Pill Tretinoin Cream Online Prices Simplicef In Poland Simplicef Shipped From Canada Can You Buy Testosterone Booster Strips Usa Yes Here Online Phenergan Shopping Phenergan Online Fast Shipping Buying Zyban In Usa Free Viagra Sample Pills Sublingual Viagra Best Price Uk No Prescription Uk Sublingual Viagra