Monday, 26 November 2012

Change password function in wordpress


function wp_set_password($password,$user_id)
{
       global $wpdb;
       $newpassword = ltrim( $_POST['newpassword']) ;
       $hash = wp_hash_password( $newPassword ) ;
       $wpdb->update( $wpdb->users, array('user_pass' => $hash , 'user_activation_key' => '') , array('ID' => $user_id )) ;

        wp_cache_delete($user_id,'users');
}


 
 

Sunday, 14 October 2012

Loading overlay before page complete load

Place the below code at the top of  your respective page and copy image to your image folder.
Then load your page again.


<style>
 .progress-indicator {
   top:0;
   right:0;
   width:100%;
   height:100%;
   position:fixed;
   text-align:center;
   /* IE filter */
   filter: progid:DXImageTransform.Microsoft.Alpha(opacity=50);
   -moz-opacity:1.0;    /* Mozilla extension */
   -khtml-opacity:1.0;  /* Safari/Conqueror extension */
   opacity:1.0; /* CSS3 */
   z-index:1000;
   background-color:white;
   display:none;
 }

 .progress-indicator img {
   margin-top:150px;
 }
 .progress-indicator h1 {
   font-size:16px;
   font-weight:bold;
   margin-top:50px;
 }
</style>

<div class="progress-indicator">
   <img src="/images/icon_loading_75x75.gif'" alt="" />
   <h1>Loading.....</h1>
</div>

<script>
jQuery(document).ready(function() {
    jQuery('.progress-indicator').show();
    jQuery(window).load(function() { jQuery('.progress-indicator').hide(); });
});
</script>
 





Tuesday, 26 June 2012

Convert milliseconds in to days,hours,minute, seconds

  
    var now = new Date(); // Return current date and time
    var future = new Date(now.setHours(now.getHours()+24));  // add 24 hours in present time .
    var diff = Math.abs(future - now); // return diff in milliseconds

    var secs = Math.floor(diff / 1000);
    var mins = Math.floor(secs / 60);
    secs = secs % 60;
    var hrs = Math.floor(mins / 60);
    mins = mins % 60;
    var days = Math.floor(hrs / 24);
    hrs = hrs % 24;

    str =    future.toString();
    str += '<br>'+days+' days '+hrs+' hours '+mins+' minutes '+secs+' seconds';


Substract date in js

 
    var now = new Date();
    //It will give the current date and time in default format.
 
    var future = new Date(now .setHours(now .getHours()+24));
    //in this we add 24 hours in present time .
 
    var diff = Math.abs(future - now);
 
   diff in milliseconds.

Parse Date in JS


var x = new Date(Date.parse("Jun 28 2012"));
 It will return :-
                     Wed Jun 27 2012 00:00:00 GMT+0530


And  var x = new Date(Date.parse("Jun 28 2012 14:00:00"));
 It will return :-
                     Wed Jun 28 2012 14:00:00 GMT+0530

 

Tuesday, 17 April 2012

Java Script to allow Only Numbers

This function allow only numbers, dot and dashes. If you want only numbers then remove
".-" from var strValidChars = "0123456789.-"; .


function IsNumeric(strString)
// check for valid numeric strings
{
    var strValidChars = "0123456789.-";
    var strChar;
    var blnResult = true;
   
    if (strString.length == 0) return false;
   
    // test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++)
    {
    strChar = strString.charAt(i);
    if (strValidChars.indexOf(strChar) == -1)
    {
    blnResult = false;
    }
    }
    return blnResult;
}

Friday, 17 February 2012

compact() or set multiple values in cake php

set() ,method is the main way to send data from your controller to your view. Once you
have used set(),the variable can be access in your view.

Syntex of set is-> "set('variable','value')"

In Cake-php's controller's file you set the variable for accessing in view's file as-

<?php
  $this->set('variable1','value1');
  $this->set('variable2','value2');
  $this->set('variable3','value3');
?>

There is another way to set multiple variables for the same page, By using "compact()" funtion.

In Cake-php's controller's file you write this as-

<?php
    $this->set(compact('variable1','variable2,''variable3'....));
?>

The compact() function creates an array from variables and their values.
And you can access these set variable as in view's file...

<?php
   echo $variable1;
   echo $variable2;
...........
?>




Wednesday, 15 February 2012

Jquery to call function on 'onchange' property of select(combobox)

<script>
        $(document).ready(function(){
                   $('#language').change(function(){
                         lang()
                 });
         })

       function lang()
       {
             alert('hi, it is called function.....');
       }
</script>

Tuesday, 3 January 2012

Java Script for 'email' validation

This is function for validate the email enter by user.
It return true if email address is right or
false if entered mail is not in proper way. 
\\ Email Validation

function validate(form_id,email) {
 
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\
            .([A-Za-z]{2,4})$/;
var address = document.forms[form_id].elements[email].value; 
   if(reg.test(address) == false) {
      alert('Invalid Email Address');
      return false
}
else return true;
}