$url=’https://maps.googleapis.com/maps/api/place/textsearch/json?query=’.$query1.’&sensor=true&key=’.$key;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response_a = json_decode($response);
echo ‘<pre/>’; print_r($response_a); die;
Author Archives: admin
Add Ad-dons Data
add_filter( ‘woocommerce_add_cart_item_data’,’add_cart_item_data1′,10,2);
function add_cart_item_data1($cart_item_meta,$product_id) {
session_start();
global $woocommerce;
$cart_step_deta = array();
foreach($_SESSION[‘step_data’] as $step){
foreach($step as $step_itm):
$catname = get_customization_cat_name($step_itm[‘stepcat’],$product_id);
$cusprice = get_customization_price($step_itm[‘stepcat’],$step_itm[‘catpost’],$product_id);
$cart_step_deta[]=array(‘name’=>$catname,’price’=>$cusprice,’value’=> get_the_title($step_itm[‘catpost’]));
endforeach;
}
foreach($_SESSION[‘measurement’] as $mkey => $mvalues){
$measurement_deta[]=array(‘name’=>str_replace(‘_’,’ ‘,$mkey),’price’=>0,’value’=>$mvalues);
}
$cart_item_meta=array(‘cart_step_deta’=>$cart_step_deta,’measurement_deta’=>$measurement_deta);
unset($_SESSION[‘step_data’]);
unset($_SESSION[‘measurement’]);
unset($_SESSION[‘custom_step’]);
unset($_SESSION[‘custom_product’]);
unset($_SESSION[‘step_taxoid’]);
unset($_SESSION[‘step_taxo’]);
return $cart_item_meta;
}
add_filter(‘woocommerce_get_cart_item_from_session’,’get_cart_item_from_session1′,10,2);
function get_cart_item_from_session1($cart_item,$values) {
if ( ! empty( $values[‘cart_step_deta’] ) ) {
$cart_item[‘cart_step_deta’] = $values[‘cart_step_deta’];
$cart_item[‘measurement_deta’] = $values[‘measurement_deta’];
$cart_item = add_cart_item1( $cart_item );
}
return $cart_item;
}
add_filter( ‘woocommerce_add_cart_item’,’add_cart_item1′,10,1);
function add_cart_item1( $cart_item ) {
if (isset($cart_item[‘cart_step_deta’])) :
$extra_cost = 0;
foreach ($cart_item[‘cart_step_deta’] as $addon) :
if ($addon[‘price’]>0) $extra_cost += $addon[‘price’];
endforeach;
$cart_item[‘data’]->adjust_price( $extra_cost );
endif;
return $cart_item;
}
add_filter( ‘woocommerce_get_item_data’,’get_item_data1′, 10, 2 );
function get_item_data1( $other_data, $cart_item ) {
if (isset($cart_item[‘cart_step_deta’])) :
foreach ($cart_item[‘cart_step_deta’] as $addon) :
$name = $addon[‘name’];
if ($addon[‘price’]>0) $name .= ‘ (‘ . woocommerce_price($addon[‘price’]) . ‘)’;
$other_data[] = array(
‘name’ => $name,
‘value’ => $addon[‘value’],
‘display’ => isset($addon[‘display’]) ? $addon[‘display’] : ”
);
endforeach;
endif;
return $other_data;
}
Infinite Ajax Scroll
jQuery.ias({
container : 'ul.products',
item: '.myproducts',
pagination: 'nav.woocommerce-pagination',
next: 'ul.page-numbers li.woonextpage a', //'ul.page-numbers li a:first'
loader: '<img src="<?php bloginfo('template_url'); ?>/images/ajax-loader.gif"/>',
});
wp_list_categories pagination
<?php
$args = array(
'taxonomy' => 'categories',
'orderby' => 'term_group',
'hide_empty' => 0,
'hierarchical' => 1,
'exclude' => '16',
'parent' => '0',
);
$categories = get_categories($args);
$numOfItems = 60;
$page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;
$to = $page * $numOfItems;
$current = $to - $numOfItems;
$total = sizeof($categories);
echo '<ul>';
for ($i=$current; $i<$to; ++$i) {
$category = $categories[$i];
if ($category->name) { echo '<li><a href="' . get_term_link($category->slug, 'categories') . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></li>';}
}
echo '</ul>';
unset($category);
echo paginate_links( array(
'base' => add_query_arg( 'cpage', '%#%' ),
'format' => '',
'prev_text' => __('«'),
'next_text' => __('»'),
'total' => ceil($total / $numOfItems),
'current' => $page
));
?>
Adding Custom Fields In WordPress Comment Form
<?php
// Add custom meta (ratings) fields to the default comment form
// Default comment form includes name, email and URL
// Default comment form elements are hidden when user is logged in
add_filter(‘comment_form_default_fields’,’custom_fields’);
function custom_fields($fields) {
$commenter = wp_get_current_commenter();
$req = get_option( ‘require_name_email’ );
$aria_req = ( $req ? ” aria-required=’true'” : ” );
$fields[ ‘author’ ] = ‘<p class=”comment-form-author”>’.
‘<label for=”author”>’ . __( ‘Name’ ) . ‘</label>’.
( $req ? ‘<span class=”required”>*</span>’ : ” ).
‘<input id=”author” name=”author” type=”text” value=”‘. esc_attr( $commenter[‘comment_author’] ) .
‘” size=”30″ tabindex=”1″‘ . $aria_req . ‘ /></p>’;
$fields[ ’email’ ] = ‘<p class=”comment-form-email”>’.
‘<label for=”email”>’ . __( ‘Email’ ) . ‘</label>’.
( $req ? ‘<span class=”required”>*</span>’ : ” ).
‘<input id=”email” name=”email” type=”text” value=”‘. esc_attr( $commenter[‘comment_author_email’] ) .
‘” size=”30″ tabindex=”2″‘ . $aria_req . ‘ /></p>’;
$fields[ ‘url’ ] = ‘<p class=”comment-form-url”>’.
‘<label for=”url”>’ . __( ‘Website’ ) . ‘</label>’.
‘<input id=”url” name=”url” type=”text” value=”‘. esc_attr( $commenter[‘comment_author_url’] ) .
‘” size=”30″ tabindex=”3″ /></p>’;
$fields[ ‘phone’ ] = ‘<p class=”comment-form-phone”>’.
‘<label for=”phone”>’ . __( ‘Phone’ ) . ‘</label>’.
‘<input id=”phone” name=”phone” type=”text” size=”30″ tabindex=”4″ /></p>’;
return $fields;
}
// Add fields after default fields above the comment box, always visible
add_action( ‘comment_form_logged_in_after’, ‘additional_fields’ );
add_action( ‘comment_form_after_fields’, ‘additional_fields’ );
function additional_fields () {
echo ‘<p class=”comment-form-title”>’.
‘<label for=”title”>’ . __( ‘Comment Title’ ) . ‘</label>’.
‘<input id=”title” name=”title” type=”text” size=”30″ tabindex=”5″ /></p>’;
echo ‘<p class=”comment-form-rating”>’.
‘<label for=”rating”>’. __(‘Rating’) . ‘<span class=”required”>*</span></label>
<span class=”commentratingbox”>’;
for( $i=1; $i <= 5; $i++ )
echo ‘<span class=”commentrating”><input type=”radio” name=”rating” id=”rating” value=”‘. $i .'”/>’. $i .'</span>’;
echo'</span></p>’;
}
// Save the comment meta data along with comment
add_action( ‘comment_post’, ‘save_comment_meta_data’ );
function save_comment_meta_data( $comment_id ) {
if ( ( isset( $_POST[‘phone’] ) ) && ( $_POST[‘phone’] != ”) )
$phone = wp_filter_nohtml_kses($_POST[‘phone’]);
add_comment_meta( $comment_id, ‘phone’, $phone );
if ( ( isset( $_POST[‘title’] ) ) && ( $_POST[‘title’] != ”) )
$title = wp_filter_nohtml_kses($_POST[‘title’]);
add_comment_meta( $comment_id, ‘title’, $title );
if ( ( isset( $_POST[‘rating’] ) ) && ( $_POST[‘rating’] != ”) )
$rating = wp_filter_nohtml_kses($_POST[‘rating’]);
add_comment_meta( $comment_id, ‘rating’, $rating );
}
// Add the filter to check if the comment meta data has been filled or not
add_filter( ‘preprocess_comment’, ‘verify_comment_meta_data’ );
function verify_comment_meta_data( $commentdata ) {
if ( ! isset( $_POST[‘rating’] ) )
wp_die( __( ‘Error: You did not add your rating. Hit the BACK button of your Web browser and resubmit your comment with rating.’ ) );
return $commentdata;
}
//Add an edit option in comment edit screen
add_action( ‘add_meta_boxes_comment’, ‘extend_comment_add_meta_box’ );
function extend_comment_add_meta_box() {
add_meta_box( ‘title’, __( ‘Comment Metadata – Extend Comment’ ), ‘extend_comment_meta_box’, ‘comment’, ‘normal’, ‘high’ );
}
function extend_comment_meta_box ( $comment ) {
$phone = get_comment_meta( $comment->comment_ID, ‘phone’, true );
$title = get_comment_meta( $comment->comment_ID, ‘title’, true );
$rating = get_comment_meta( $comment->comment_ID, ‘rating’, true );
wp_nonce_field( ‘extend_comment_update’, ‘extend_comment_update’, false );
?>
<p>
<label for=”phone”><?php _e( ‘Phone’ ); ?></label>
<input type=”text” name=”phone” value=”<?php echo esc_attr( $phone ); ?>” class=”widefat” />
</p>
<p>
<label for=”title”><?php _e( ‘Comment Title’ ); ?></label>
<input type=”text” name=”title” value=”<?php echo esc_attr( $title ); ?>” class=”widefat” />
</p>
<p>
<label for=”rating”><?php _e( ‘Rating: ‘ ); ?></label>
<span class=”commentratingbox”>
<?php for( $i=1; $i <= 5; $i++ ) {
echo ‘<span class=”commentrating”><input type=”radio” name=”rating” id=”rating” value=”‘. $i .'”‘;
if ( $rating == $i ) echo ‘ checked=”checked”‘;
echo ‘ />’. $i .’ </span>’;
}
?>
</span>
</p>
<?php
}
// Update comment meta data from comment edit screen
add_action( ‘edit_comment’, ‘extend_comment_edit_metafields’ );
function extend_comment_edit_metafields( $comment_id ) {
if( ! isset( $_POST[‘extend_comment_update’] ) || ! wp_verify_nonce( $_POST[‘extend_comment_update’], ‘extend_comment_update’ ) ) return;
if ( ( isset( $_POST[‘phone’] ) ) && ( $_POST[‘phone’] != ”) ) :
$phone = wp_filter_nohtml_kses($_POST[‘phone’]);
update_comment_meta( $comment_id, ‘phone’, $phone );
else :
delete_comment_meta( $comment_id, ‘phone’);
endif;
if ( ( isset( $_POST[‘title’] ) ) && ( $_POST[‘title’] != ”) ):
$title = wp_filter_nohtml_kses($_POST[‘title’]);
update_comment_meta( $comment_id, ‘title’, $title );
else :
delete_comment_meta( $comment_id, ‘title’);
endif;
if ( ( isset( $_POST[‘rating’] ) ) && ( $_POST[‘rating’] != ”) ):
$rating = wp_filter_nohtml_kses($_POST[‘rating’]);
update_comment_meta( $comment_id, ‘rating’, $rating );
else :
delete_comment_meta( $comment_id, ‘rating’);
endif;
}
// Add the comment meta (saved earlier) to the comment text
// You can also output the comment meta values directly in comments template
add_filter( ‘comment_text’, ‘modify_comment’);
function modify_comment( $text ){
$plugin_url_path = WP_PLUGIN_URL;
if( $commenttitle = get_comment_meta( get_comment_ID(), ‘title’, true ) ) {
$commenttitle = ‘<strong>’ . esc_attr( $commenttitle ) . ‘</strong><br/>’;
$text = $commenttitle . $text;
}
if( $commentrating = get_comment_meta( get_comment_ID(), ‘rating’, true ) ) {
$commentrating = ‘<p class=”comment-rating”> <img src=”‘. $plugin_url_path .
‘/ExtendComment/images/’. $commentrating . ‘star.gif”/><br/>Rating: <strong>’. $commentrating .’ / 5</strong></p>’;
$text = $text . $commentrating;
return $text;
} else {
return $text;
}
}
Automatically Set the Featured Image in WordPress
function wpforce_featured() {
global $post;
$already_has_thumb = has_post_thumbnail($post->ID);
if (!$already_has_thumb) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment_id);
}
}
}
} //end function
add_action('the_post', 'wpforce_featured');
add_action('save_post', 'wpforce_featured');
add_action('draft_to_publish', 'wpforce_featured');
add_action('new_to_publish', 'wpforce_featured');
add_action('pending_to_publish', 'wpforce_featured');
add_action('future_to_publish', 'wpforce_featured');
Extend Search to Include Custom Fields without Plugin
function custom_search_where($pieces) { // filter to select search query if (is_search() && !is_admin()) { global $wpdb; $custom_fields = array('field1','field2'); $keywords = explode(' ', get_query_var('s')); $query = ""; foreach ($custom_fields as $field) { foreach ($keywords as $word) { $query .= "((mypm1.meta_key = '".$field."')"; $query .= " AND (mypm1.meta_value LIKE '%{$word}%')) OR "; } } if (!empty($query)) { // add to where clause $pieces['where'] = str_replace("(((wp_posts.post_title LIKE '%", "( {$query} ((wp_posts.post_title LIKE '%", $pieces['where']); $pieces['join'] = $pieces['join'] . " INNER JOIN {$wpdb->postmeta} AS mypm1 ON ({$wpdb->posts}.ID = mypm1.post_id)"; } } return ($pieces); } add_filter('posts_clauses', 'custom_search_where', 20, 1);
All plugin hooks in WordPress 3.5
Force CSS changes to “go live” immediately
<link rel=”stylesheet” href=”<?php bloginfo(‘stylesheet_url’); echo ‘?’ . filemtime( get_stylesheet_directory() . ‘/style.css’); ?>” type=”text/css” media=”screen, projection” />
This automatically updates the ?12345678
ending part every time you modify the file. Boom. Now everyone instantly sees your changes.
Thickbox support in front end
Thickbox is as jQuery plugin that WordPress use as it’s main popup window or modal view. It’s already built-in in WordPress so why not use that in front end. No need to download or import any extra files.
Hook that with a function
add_action('init', 'myplugin_thickbox'); function myplugin_thickbox() { if (! is_admin()) { wp_enqueue_script('thickbox', null, array('jquery')); wp_enqueue_style('thickbox.css', '/'.WPINC.'/js/thickbox/thickbox.css', null, '1.0'); } } To add Thickbox, we only need to add class=”thickbox” and it will automatically add the onclick trigger. <a title="Title" href="http://vsjodha.com/wp-content/uploads/2012/02/google_uwt.png">Google search</a>