Sunday 3 April 2016

How can I replace whitespace with underscores in php?

The \s character class will match whitespace characters. I've added the + quantifier to collapse multiple whitespace to one _. If you don't want that, remove the +

$picture =preg_replace('/\s+/', '_', uniqid()."_".$image_name);

Wednesday 30 March 2016

Custom Url ReWrite in Wordpress

here Example How To generate custom url rewrite in wordpress

Check it

function create_custom_rewrite_rules() {
global $wp_rewrite;

$rewrite_tag = '%patentID%';
$wp_rewrite->add_rewrite_tag( $rewrite_tag, '(.+?)', 'patentID=' );
$rewrite_keywords_structure = $wp_rewrite->root . "%pagename%/$rewrite_tag/";
$new_rule = $wp_rewrite->generate_rewrite_rules( $rewrite_keywords_structure );

$wp_rewrite->rules = $new_rule + $wp_rewrite->rules;

return $wp_rewrite->rules;
}

function add_custom_page_variables( $public_query_vars ) {
$public_query_vars[] = 'patentID';

return $public_query_vars;

}

function flush_rewrite_rules132() {

global $wp_rewrite;

$wp_rewrite->flush_rules();

}

add_action( 'init', 'flush_rewrite_rules132' );
add_action( 'generate_rewrite_rules', 'create_custom_rewrite_rules' );
add_filter( 'query_vars', 'add_custom_page_variables' );


You can get this using

$patentID = get_query_var('patentID');  in you template

Tuesday 22 March 2016

added custom loder in ajax request in wordpress

added custom loder in ajax request in wordpress

function ajaxindicatorstart(text)
{
if(jQuery('body').find('#resultLoading').attr('id') != 'resultLoading'){
jQuery('body').append('<div id="resultLoading" style="display:none"><div><img src="<?php echo wp_get_attachment_url( 391 ); ?>"><div>'+text+'</div></div><div class="bg"></div></div>');
}

jQuery('#resultLoading').css({
'width':'100%',
'height':'100%',
'position':'fixed',
'z-index':'10000000',
'top':'0',
'left':'0',
'right':'0',
'bottom':'0',
'margin':'auto'
});

jQuery('#resultLoading .bg').css({
'background':'#000000',
'opacity':'0.7',
'width':'100%',
'height':'100%',
'position':'absolute',
'top':'0'
});

jQuery('#resultLoading>div:first').css({
'width': '250px',
'height':'75px',
'text-align': 'center',
'position': 'fixed',
'top':'0',
'left':'0',
'right':'0',
'bottom':'0',
'margin':'auto',
'font-size':'16px',
'z-index':'10',
'color':'#ffffff'

});

    jQuery('#resultLoading .bg').height('100%');
        jQuery('#resultLoading').fadeIn(300);
    jQuery('body').css('cursor', 'wait');
}

function ajaxindicatorstop()
{
    jQuery('#resultLoading .bg').height('100%');
        jQuery('#resultLoading').fadeOut(300);
    jQuery('body').css('cursor', 'default');
}
jQuery(document).ajaxStart(function () {
   //show ajax indicator
ajaxindicatorstart('please wait..');
  }).ajaxStop(function () {
//hide ajax indicator
ajaxindicatorstop();
  });

Wednesday 16 March 2016

Insert custom post data with custom field using ajax in wordpress

Insert custom post data  with custom field using ajax in wordpress



<!-- This code in your custom template -->

<script>
 jQuery(document).ready(function() {
var form = jQuery( "#newCustomerForm" );


jQuery('.alu1').click(function(){

  var  checkForm = form.valid();
 
  if(checkForm != false){

var newCustomerForm = jQuery('#newCustomerForm').serializeArray();
jQuery.ajax({
url: "<?php bloginfo('wpurl') ?>/wp-admin/admin-ajax.php",
type:'POST',
data: newCustomerForm,
success: function(data){

if(data == "success"){


}
jQuery("form").trigger("reset");
}


});
}
return false;
});
 });
</script>
<form name="test" id="newCustomerForm">
                              <div class="input-group">
                              <span class="input-group-addon"><i class="fa fa-user"></i></span>
                              <input  class="form-control" type="text" placeholder="Enter your name" name="alu_name" required="required" />
                             
                              </div>
                              <div class="input-group">
                              <span class="input-group-addon"><i class="fa fa-envelope-o"></i></span>
                             
                                <input id="exampleInputEmail1" class="form-control" type="email" placeholder="Enter your Email" name="alu_email" required="required" />
                                </div>
                               
                                <div class="input-group">
                              <span class="input-group-addon"><i class="fa fa-mobile"></i></span>
                                <input  class="form-control" type="number" placeholder="Enter your Mobile no" name="alu_mobile" required="required" />
                                </div>
                               
                                <div class="input-group">
                              <span class="input-group-addon"><i class="fa fa-university"></i></span>
                                <input  class="form-control" type="text" placeholder="Enter your city name" name="alu_city" required="required" />
                                </div>
                               
                                <div class="input-group">
                              <span class="input-group-addon"><i class="fa fa-commenting"></i></span>
                                <textarea id="exampleTextarea" class="form-control" rows="3" name="alu_message" required="required"></textarea>
                                </div>
                                <button type="button" class="btn primary alu1">Submit</button>
                                 <input type="hidden" name="submitted" id="submitted" value="true" />
    <input type="hidden" name="nonce" value="<?php echo wp_create_nonce( 'form-nonce' );?>" />  
                            <input type="hidden" name="action" id="my_action" value="my_action" />                   
                                </form>
   
   
   
   
    <?php                           

/** In Your Function File **/
              function myFunction(){
   //do something
  
  
  
 
  

$alu_name=    sanitize_meta('name_alu_c1',$_POST['alu_name'],'user');
$alu_email=    sanitize_email($_POST['alu_email']);
$alu_mobile=    sanitize_meta('phone_alu_c1',$_POST['alu_mobile'],'user');
$alu_city=    sanitize_meta('city_alu_c1',$_POST['alu_city'],'user');
$alu_message=    sanitize_meta('message_alu_c1',$_POST['alu_message'],'user');

$my_cptpost_args = array(
          
            'post_title' => $alu_name,
            'post_status'   => 'publish',
            'post_type' => "alu_contact1",
);
$cpt_id = wp_insert_post($my_cptpost_args, $wp_error );
if($cpt_id){
add_post_meta($cpt_id, 'name_alu_c1', $alu_name, true);//here insert two custom field data.
add_post_meta($cpt_id, 'email_address_alu_c1', $alu_email, true);//here insert two custom field data.
add_post_meta($cpt_id, 'phone_alu_c1', $alu_mobile, true);//here insert two custom field data.
add_post_meta($cpt_id, 'city_alu_c1', $alu_city, true); //here insert two custom field data..
add_post_meta($cpt_id, 'message_alu_c1', $alu_message, true); //here insert two custom field data..

$test = wp_mail( $alu_email, "Contact Us", "Thank You For Contact us" );

echo "success";
}
       
       
   die();
}





add_action('wp_ajax_my_action', 'myFunction');           // for logged in user
add_action('wp_ajax_nopriv_my_action', 'myFunction');    // if user not logged in  

Sunday 13 March 2016

how to add custom column in wordpress categoty or texonomy admin panel in wordpress

how to add custom column in wordpress categoty or texonomy admin panel in wordpress


// product-category is my custom category change your texonomy
add_filter("manage_edit-product-category_columns", 'theme_columns');

function theme_columns($theme_columns) {
    $new_columns = array(
        'cb' => '<input type="checkbox" />',
        'name' => __('Name'),
        'category' => 'Category Banner',
      'description' => __('Description'),
        'slug' => __('Slug'),
        'posts' => __('Posts')
        );
    return $new_columns;
}


add_filter("manage_product-category_custom_column", 'manage_theme_columns', 10, 3);

function manage_theme_columns($out, $column_name, $theme_id) {
    $theme = get_term($theme_id, 'product-category');


global $post;

    switch ($column_name) {
        case 'category':
            // get header image url

           $variable = get_field( 'category_image', 'product-category_'.$theme_id );//here advace customfield value you can use your custom field;
           if(!empty($variable)){
            $out .= "<img src=".$variable." height='83px' width='150px'/>";
   }
            break;

        default:
            break;
    }
    return $out;   
}

How to chnage character lenght and continue reading text in excerpt in wordpress

How to chnage character lenght and continue reading text in excerpt in wordpress


if you have child theme first remove this filter  i have twenty thierteen theme

function child_theme_setup() {
// override parent theme's 'more' text for excerpts
remove_filter( 'excerpt_more', 'twentythirteen_excerpt_more' );

}
add_action( 'after_setup_theme', 'child_theme_setup' );

after change character lenght in wordpress

function et_excerpt_length($length) {
    return 70;
}
add_filter('excerpt_length', 'et_excerpt_length');

you can change the text of continue reading

function et_excerpt_more($more) {
    global $post;
    return '<a href="'. get_permalink($post->ID) . '" class="view-full-post-btn"> read more....</a>';
}
add_filter('excerpt_more', 'et_excerpt_more');

How to Add Js and css In footer in Wordpress

How to Add Js and css In footer in Wordpress


/** Footer add js and css in wordpress
function prefix_add_footer_styles() {

wp_enqueue_script( 'js-name', get_stylesheet_directory_uri() . 'your js path',array('jquery'),'',true);
wp_enqueue_style( 'css-name', get_stylesheet_directory_uri(). 'yor css path' );
  
};
add_action( 'get_footer', 'prefix_add_footer_styles' );

**/

Thursday 10 March 2016

add smooth scrolling using jquery in menu

Hello Here example Add Smooth scroll menu in menu

simple add this js in your page. check it it. it working file

but you need to add jquery.easing.min.js in your header after jquery

jQuery(function() {
    jQuery('a[href*="#"]:not([href="#"])').click(function() {
      if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
        var target = jQuery(this.hash);
        target = target.length ? target : jQuery('[name=' + this.hash.slice(1) +']');
        if (target.length) {
          jQuery('html, body').animate({
            scrollTop: target.offset().top
          }, 1000);
          return false;
        }
      }
    });
  });

Tuesday 16 February 2016

image upload with compress image and add text into image in using php

Hello Here Example Image compress and add text into image

<?php
function compress_image($source_url, $destination_url, $quality) {
  $info = getimagesize($source_url);
if ($info['mime'] == 'image/jpeg') $image = imagecreatefromjpeg($source_url);
elseif ($info['mime'] == 'image/gif') $image = imagecreatefromgif($source_url);
elseif ($info['mime'] == 'image/png') $image = imagecreatefrompng($source_url);
 // Set Path to Font File
$color = imagecolorallocate($image, 255, 255, 255);

//x-coordinate of the upper left corner.
$xPos = 600;
//y-coordinate of the upper left corner.
$yPos = 200;

//Writting the picture
imagestring($image,5,$xPos,$yPos,"Add Your Text Here",$color);
imagejpeg($image, $destination_url, $quality);



return  $destination_url;
}
if(isset($_POST['submit'])){
$tempPath = $_FILES['upload']['tmp_name'];
$mypath = "compress";
if(!is_dir($mypath)){
mkdir($mypath);
}
 $filename = $_FILES['upload']['name'];
 $destination = $mypath."/".$filename;

$destination  =   compress_image($tempPath,$destination,90);
}
?>

<form method="post" enctype="multipart/form-data">

<input type="file" name="upload"/>
<input type="submit" name="submit" value="upload"/>

</form>

Friday 5 February 2016

How to pass variables via PHP CURL

How to pass variables via PHP CURL

$message="Thank you";
$phone = 123456789;
$url = 'http://example.com';


$fields = array('phone'=>$phone,'source'=>'test','message'=>$message);
$fields_string='';


foreach($fields as $key=>$value) {  $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');


$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);