WordPress cron job for updating your task automatic in 5 min time basis

here is code used for Cron job.

function my_cron_schedules($schedules) {
if (!isset($schedules[“5min”])) {
$schedules[“5min”] = array(
‘interval’ => 5 * 60,
‘display’ => __(‘Once every 5 minutes’));
if (!isset($schedules[“30min”])) {
$schedules[“30min”] = array(
‘interval’ => 30 * 60,
‘display’ => __(‘Once every 30 minutes’));
return $schedules;


add_filter(‘cron_schedules’, ‘my_cron_schedules’);



if (!wp_next_scheduled(‘my_schedule_hook’)) {
wp_schedule_event(time(), ‘5min’, ‘my_schedule_hook’);
add_action(‘my_schedule_hook’, ‘my_task_function’);


function my_task_function() {
*  Check user FFl date crossed current time or not
*  IF matched any user of FFL expired date

$args_new = array(
‘meta_query’ => array(
‘relation’ => ‘AND’,
‘key’ => ‘wpcf-is_ffl_verified’,
‘value’ => ‘1’,
‘compare’ => ‘=’
‘key’ => ‘wpcf-ffl-expiration-date’,
‘value’ => time(),
‘compare’ => ‘<=’
// The Query
$user_query = new WP_User_Query($args_new);

// User Loop
if (!empty($user_query->get_results())) {
foreach ($user_query->get_results() as $user) {
* Set all post not FFL verified
$user_id = $user->ID;
$exp = get_user_meta( $user_id, ‘wpcf-ffl-expiration-date’,true);

$args_get_post = array(
‘post_type’ => array(‘firearms’),
‘author’ => $user_id
// Current User post update in to FFL Verified yes
$current_user_posts = query_posts($args_get_post);

foreach ($current_user_posts as $row) {
update_post_meta($row->ID, ‘ffl_verified’, ‘0’);

* set user is no more FFL verified
* New post FFL is depends on this value
update_user_meta($user_id, ‘wpcf-is_ffl_verified’,’0′);

* See the post type older request form value
* and send it to trash
$args_user_ffl = array(
‘post_type’ => ‘user-ffl’,
‘author’ =>$user_id
//’post_status’ => array(‘publish’, ‘pending’, ‘draft’)
$wp_ffl_posts = get_posts($args_user_ffl);

* remove previous requested user FFL information
* may be set to pending
if (count($wp_ffl_posts)>0){

*  Email format sent to user
$to = trim($user->user_email);

$expired_readable = date(‘F ,j Y’, $exp);

$subject = ‘FFL Expired  !’;
$body = ‘<br/> Hello ‘.$user->user_nicename.’! <br/>’
. ‘Your FFL is expire on ‘ . $expired_readable . ”
. ‘<br/>Your all Firearms post will be invisible on site. ‘
. ‘<br/>You are requested to submit valid FFL for continuing to publish Firearms posts.’
. ‘<br/><br/>’
. ‘Thanks ‘
. ‘<br/>’
. ‘Web Admin <br/>’ .get_site_url();
$headers = array(‘Content-Type: text/html; charset=UTF-8’);

wp_mail($to, $subject, $body, $headers);






NextGen WordPress Gallery Plugin Shortcode details

NextGEN Gallery is used to create dynamic image gallery having multiple Galleries, Albums, Images for wordpress website. You may enjoy to use this gallery for reducing hurdle for making your own or searching other gallery plugins.
But you must have knowledge to display image in your post or page of wordpress site. I have posted some shortcode which are used to show gallery with different layout.


Download now NextGen Gallery (nextgen-gallery.2.2.12.zip) Download from here or Click here for download from wordpress.


NextGEN 2.0 introduces a new short code structure. This page describes everything you need to know to work fluidly with the new shortcodes.

We should start by emphasizing that you can now customize your galleries easily using the new Insert Gallery Window in your text editor. For the most part, you never need to use shortcodes again if you don’t want to.

The main places we think people may want to use these are:

  • Widgets. You can’t use the Insert Gallery Window within a widget, so you’d need to use a shortcode. 
  • Page/Post Text Editor. If you prefer to use the text-based editor for pages or posts, you currently need to work with shortcodes, or go back and forth between visual and text editor. We are working on making the Insert Gallery Window more robust for use with text-based editing.

Let’s start with a sample shortcode that includes a lot of options.


[ngg_images gallery_ids=”1″ display_type=”photocrati-nextgen_basic_slideshow” exclusions=”4,6″ gallery_width=”600″ gallery_height=”400″]



The shortcode above will display gallery #1 as a NextGEN Gallery basic slideshow. It will exclude images #4 and #6 and will set the slideshow size as 600px X 400px. So that gives you a sense for what the shortcodes will look like. Now lets break them down.


This is the parameter that now introduces every NextGEN Gallery shortcode.


Following the ngg_images tag, identify is the source of the images you want to display. There are several options for the image source.

  • gallery_ids=”1,3″   (retrieves galleries #1 and #3)
  • album_ids=”1″   (retrieves album #1)
  • tag_ids=”landscapes,florida beaches”   (retrieves images tagged ‘landscapes’ or ‘florida beaches’)
  • image_ids=”2,3,5″   (retrieves images 2, 3, and 5)
  • source=”recent”   (retrieves recently uploaded images)
  • source=”random”   (retrieves a random set of images from all galleries)

You can also chose to include or exclude specific images based on their ids.

  • gallery_ids=”1,3″ exclusions=”4,6″   (excludes images #4 and #6)
  • album_ids=”1,2″ exclusions=”a1″   (excludes sub album #1)


Following the image source, specify the display type. Here is a list of all available display types in NextGEN Gallery and NextGEN Pro.

  • display_type=”photocrati-nextgen_basic_slideshow”
  • display_type=”photocrati-nextgen_basic_thumbnails”
  • display_type=”photocrati-nextgen_basic_imagebrowser”
  • display_type=”photocrati-nextgen_basic_singlepic”
  • display_type=”photocrati-nextgen_basic_extended_album”
  • display_type=”photocrati-nextgen_basic_compact_album”
  • display_type=”photocrati-nextgen_pro_slideshow”
  • display_type=”photocrati-nextgen_pro_thumbnail_grid”
  • display_type=”photocrati-nextgen_pro_horizontal_filmstrip”
  • display_type=”photocrati-nextgen_pro_film”
  • display_type=”photocrati-nextgen_pro_blog_gallery”
  • display_type=”photocrati-nextgen_pro_list_album”
  • display_type=”photocrati-nextgen_pro_grid_album”
  • display_type=”photocrati-nextgen_pro_masonry”


For each NextGEN Gallery type, there is a large range of parameters and settings you can apply. These are all now visible in NextGEN Gallery 2.0’s new Insert Gallery Window. But you can also apply them using parameters within shortcodes. We are working on compiling an entirely complete list of every available shortcode parameter in NextGEN Gallery (there are a lot). For now, to give you a sense for what the options look like, consider the following parameters for slideshows and thumbnail galleries.
Example: Common Parameters for NextGEN Basic Slideshows

  • gallery_width=”600″
  • gallery_height=”400″
  • cycle_interval=”5″

Pro Slideshows

  • width=”600″
  • transition_speed=”3″
  • slideshow_speed=”2″

Example: Common Parameters for NextGEN Basic Thumbnail Gallery:

  • override_thumbnail_settings=”1″ (required to override default thumbnail setting within shortcodes)
  • thumbnail_width=”120″
  • thumbnail_height=”80″
  • thumbnail_crop=”1″
  • number_of_columns=”4″
  • show_slideshow_link=”1″
  • slideshow_link_text=”View Slideshow”

Pro Thumbnail Gallery

  • images_per_page=”10″
  • spacing=”3″
  • number_of_columns=”4″
  • ngg_triggers_display=”never”

Two general points:

  • For any parameters you do not define via shortcode, the gallery will adopt whatever default setting you have in NextGEN Gallery options panel (under Gallery > Gallery Settings). So if you don’t set the gallery width and height for a slideshow in a shortcode, the slideshow will just adopt the default gallery width and height that you’ve designated under Gallery > Gallery Settings > NextGEN Basic Slideshow.
  • For any parameters that are either Yes or No, you can use a “1” to indicate Yes or a “0” to indicate No.


Below are the standard shortcodes for NextGEN and NextGEN Pro gallery and album types. We provide this for those who would like to copy and paste the shortcodes.

NextGEN Basic Thumbnail Gallery


[ngg_images gallery_ids=”1″ display_type=”photocrati-nextgen_basic_thumbnails”]



NextGEN Basic Slideshow Gallery


[ngg_images gallery_ids=”1″ display_type=”photocrati-nextgen_basic_slideshow”]



NextGEN Basic Image Browser Gallery Gallery


[ngg_images gallery_ids=”1″ display_type=”photocrati-nextgen_basic_imagebrowser”]



NextGEN Basic SinglePic 


[ngg_images image_ids=”1″ display_type=”photocrati-nextgen_basic_singlepic”]




NextGEN Basic Tag Cloud


[ngg_images gallery_ids=”1″ display_type=”photocrati-nextgen_basic_tagcloud”]



NexGEN Basic Extended Album


[ngg_images album_ids=”2″ display_type=”photocrati-nextgen_basic_extended_album”]



NextGEN Basic Compact Album


[ngg_images album_ids=”2″ display_type=”photocrati-nextgen_basic_compact_album”]



NextGEN Pro Thumbnail Gallery


[ngg_images gallery_ids=”1″ display_type=”photocrati-nextgen_pro_thumbnail_grid”]



NextGEN Pro Slideshow Gallery


[ngg_images gallery_ids=”1″ display_type=”photocrati-nextgen_pro_slideshow”]



NextGEN Pro Filmstrip Gallery


[ngg_images gallery_ids=”1″ display_type=”photocrati-nextgen_pro_horizontal_filmstrip”]



NextGEN Pro Film Gallery


[ngg_images gallery_ids=”1″ display_type=”photocrati-nextgen_pro_film”]



NextGEN Pro Masonry


[ngg_images gallery_ids=”1″ display_type=”photocrati-nextgen_pro_masonry” size=”180″ padding=”10″]



NextGEN Pro BlogStyle Gallery


[ngg_images gallery_ids=”1″ display_type=”photocrati-nextgen_pro_blog_gallery”]



NextGEN Pro Grid Album


[ngg_images album_ids=”2″ display_type=”photocrati-nextgen_pro_grid_album”]



NextGEN Pro List Album


[ngg_images album_ids=”2″ display_type=”photocrati-nextgen_pro_list_album”]



How to optimize wordpress website

We have many option for optimizing wordpress website. From these some of them are described below:


Catching :

We can make site fast and re bust by using catching implementation on website.


Query Optimization:

Reducing unrequired column on Post table:

WordPress framework has used simple table structure. All the post and page content are inserted in single table. The content of any page and post are putting next column for revised content of individual page. If we have maxmium of this unrequired column on table it makes effect on processing time of quering process. We need to remove this unrequired column on that table .

See below the query for getting all content in individual table and unrequired column of table in the post table.

To see how much the column in that table:

select count(*) from wp_posts

where wp_post is table name.


Find unrequired revision content on table.

select count(*) from wp_posts where post_type=’revision’



Query to remove the unrequired revision column on the table.

delete from wp_posts where post_type=’revision’









Helpful web analyzer which gives detail of site load time and give suggestion to improve their performance

This post lists 3 most useful FireFox addons that will help you analyze web page load time as you browse:

1. YSlow

YSlow is the official Yahoo! addon that integrates with Firebug. YSlow analyzes web pages and suggests ways to improve their performance based on a set of rules for high performance web pages. When installed, it adds a tiny icon to FireFox status bar which shows the current page load time:



2. Google’s Page Speed

Page Speed is a Firefox/Firebug add-on that performs several tests on a site’s web server configuration and front-end code. These tests are based on a set of best practices known to enhance web page performance.

Webmasters who run Page Speed on their pages get a set of scores for each page, as well as helpful suggestions on how to improve its performance.

It adds an extra tab to Firebug that allows to analyze current page speed:



3. LORI (Life-of-Request Info)

LORI (Life-of-Request Info) is an advanced FireFox addon that adds a status bar at the bottom right corner of Firefox and displaying:

  • TTFB: how long it took to see the first byte from remote server (from click to first byte received).
  • TTC: how long it took to display the page (from click to complete drawing of the page)
  • Page size (number of bytes used to display the page): this value includes both bytes fetched from network and bytes fetched from the browser’s cache.
  • Number of requests: number of requests used to fetch the page’s content (images, style-sheet, javascript ….). Again, this value include both network requests and cache requests.

Note: it looks like it is not compatible with current FireFox version but it is a classic tool for page load time analysis so I couldn’t help mentioning it. Please comment here once the addon is updated. 


Adding Styles Css page on our plugin in Front or Admin Side

We need to initialize the function activation on loading the plugin path we have generally two option for loading the file content on initialization of plugin or initialization on admin section.

If we have object oriented concept on plugin we generally call the function on __constructor function.

public function __construct( $file )
/* Adding styles sheet page when my plugin activated for the front part */

/* Initialize on loading the admin part styles sheet */

/* Initialize when loading admin menu for the  admin part styles sheet */

add_action( ‘admin_menu’, ‘my_plugin_admin_menu’ );

function add_my_style_page(){
wp_enqueue_style(‘style-name’,  plugins_url(‘/css/style.css’,__FILE__));

function my_plugin_admin_menu() {

/* Register our plugin page */

$page = add_submenu_page( ‘edit.php’, __( ‘My Plugin’, ‘myPlugin’ ), __( ‘My Plugin’, ‘myPlugin’ ), ‘administrator’, __FILE__, ‘my_plugin_manage_menu’ );

/* Using registered $page handle to hook stylesheet loading */

add_action( ‘admin_print_styles-‘ . $page, ‘my_plugin_admin_styles’ );


function my_plugin_admin_styles() {

/* * It will be called only on your plugin admin page, enqueue our stylesheet here */

wp_enqueue_style( ‘myPluginStylesheet’ );


function my_plugin_manage_menu() {

/* Output our admin page */



Adding Content on Plugin Desciption Row

I have used the wordpress function for other detail of my plugin.  These Meta text caontent are html, link or content.  I have added the content text of Faq, Read Me, Donate Link and Other Icon for my facebook and other social media link.

Code Used

add_filter( ‘plugin_row_meta’,’pkb_advert_pop_links’,10,2);
function pkb_advert_pop_links($links, $file)
$base = plugin_basename(PKB_ADVERTISE_PLUGIN_FILE);
if ($file == $base)

$links[] = ‘<a href=”http://prakashbhandari.info.np/wordpress/wordpress-plugins/advertise-pop/”  title=”FAQ”>FAQ</a>’;
$links[] = ‘<a href=”http://prakashbhandari.info.np/wordpress/wordpress-plugins/advertise-pop/”  title=”Read Me”>README</a>’;
$links[] = ‘<a href=”http://prakashbhandari.info.np/donate/1″ title=”Donate”>DONATE</a>’;

$links[] = ‘<a href=”http://prakashbhandari.info.np/” title=”Support”></a>’;
$links[] = ‘<a href=”https://www.facebook.com/prakashkumarbhandari” title=”Facebook”></a>’;
$links[] = ‘<a href=”https://plus.google.com/110174231559558592568″ title=”+1 us on Google+”></a>’;
return $links;



Replacing the wordpress thumbnail (html) display area

WordPress have the add_filter function which can remove or add text to the relevant content area.

We have changed the Title Content and Thumbnail Image by other text or image in my project.

function pkb_my_post_image_html($html, $post_id, $post_image_id ) {

$html = “<a href='”.$pkb_replaced_thumb_href.”‘ target=’_blank’><img src='”.site_url().”/image/myimage.jpg’></a>”;

return $html;
add_filter( ‘post_thumbnail_html’, ‘pkb_my_post_image_html’, 10, 3 );


There are other filters which we use to our plugin or theme function.


Add / Remove Modify Title :

function my_title_replace_filter($title) {

return ‘My added title ::’.$title;


add_filter(‘the_title’, ‘my_title_replace_filter’ );


Add / Remove Modify Content :

function my_content_replace_filter($content) {

return ‘My added Content::’.$content;


add_filter(‘the_content’, ‘my_content_replace_filter’ );


add_action( ‘wp_head’, ‘wpcandy_actionhook_example’ );
function wpcandy_actionhook_example () {
echo ‘<meta name=”description” content=”This is the meta description for this page.” />’ ;
} // End wpcandy_actionhook_example()



Creating Custom Media Upload with user value

Customizing WordPress Media :



function provide the option for stetting up the custom value on Upload light box screen.

I have customized the Upload preference up wordpress light box for uploading audio file with it suitable lable and command.

$(document).on(‘click’, ‘.pcs_audio_upload’, function() {
current = $(this);
var post_id = current.attr(‘data-post-id’);
if( null != current) {
var pkb_uploader = wp.media({
title: ‘Service News – Select Audio file only’,
button: {
text: ‘Set Audio’
multiple: false,
}).on(‘select’, function() {

var attachment = pkb_uploader.state().get(‘selection’).first().toJSON();
var FileName = attachment.url;
var link = FileName.split(‘wp-content’);
var file_path = ‘/wp-content’+link[1];
return false;

And Next On update option of Upload button :

//Prepare frame
var frame = wp.media({
title : ‘Pick the images for this work’,
multiple : true,
library : { type : ‘image’},
button : { text : ‘Insert’ },
frame.on(‘close’,function() {
// get selections and save to hidden input plus other AJAX stuff etc.
var selection = frame.state().get(‘selection’);
frame.on(‘open’,function() {
var selection = frame.state().get(‘selection’);

//Get ids array from
ids = jQuery(‘#<?php echo $this->id; ?>’).val().split(‘,’);
ids.forEach(function(id) {
attachment = wp.media.attachment(id);
selection.add( attachment ? [ attachment ] : [] );




Enabling Date picker in WordPress form

The Date picker is user calender plugin used to display date as graphical view.  The date picker library have different types of functionality and parameter to display the date setting. Min date max date, date range, start date end date (with grater than start date).

So we already have the date picker library in wordpress. We just need to enable the library and function to show the date picker in required places.

We need to include these library stylish and jquery.

/* Include the jquery and Style sheet for the date picker */

wp_enqueue_style(‘jquery-style’, ‘http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css’);

The Includes jQuery function html structure and Id of the content which we need to make date picker enabled.


jQuery(document).ready(function() {
dateFormat : ‘yy-mm-dd’,

/* dateFormat:  0 date format year months and day */
minDate:  0

/* minDate:  0 It display only the date above system date */

dateFormat : ‘yy-mm-dd’,
beforeShow : function(){
jQuery( this ).datepicker(‘option’,’minDate’, jQuery(‘#startDate’).val() );

/*The beforeShow: it created before enable datepicker and this date picker value starts from the StartDate value (It confirms the end date must be grater than start date )*/


Html Structure of Form which is used to display the input fields.

<th><label for=”youtube”></label></th>
<td> </td>
<th><label for=”subscription_from”>Subscription From </label></th>
<td><input type=”text” id=”startDate” name=”subscription_from” id=”youtube” value=”<?php echo esc_attr( get_the_author_meta( ‘subscription_from’, $user->ID ) ); ?>” /> Year-Months-Day<br />
<th><label for=”subscription_to”>Subscription Till </label></th>
<td><input type=”text” id=”endDate” name=”subscription_to” value=”<?php echo esc_attr( get_the_author_meta( ‘subscription_to’, $user->ID ) ); ?>”/> Year-Months-Day<br />
<th><label for=”subscription_cost”>Subscription Cost </label></th>
<td><input type=”text” name=”subscription_cost” id=”subscription_cost” value=”<?php echo esc_attr( get_the_author_meta( ‘subscription_cost’, $user->ID ) ); ?>” /><br />




WordPress table and relationship diagram

Diagram above provides a visual overview of the WordPress database and the relations between the tables created during the WordPress standard. The Table Overview below includes additional details on the tables and columns.

There are 11 Table in WordPress Cms.

These are tables columns and relationship are on avobe figured.