Tuesday, July 30, 2013

difference between Action and Filter functions in wordpress

Actions are triggered by specific events that take place in WordPress, such as publishing a post, changing themes, or displaying a page of the admin panel. Your plugin can respond to the event by executing a PHP function, which might do one or more of the following:
* Modify database data
* Send an email message
* Modify what is displayed in the browser screen (admin or end-user)
Filters are functions that WordPress passes data through, at certain points in execution, just before taking some action with the data (such as adding it to the database or sending it to the browser screen). Filters sit between the database and the browser (when WordPress is generating pages), and between the browser and the database (when WordPress is adding new posts and comments to the database);

Action Hooks

Actions Hooks are intended for use when WordPress core or some plugin or theme is giving you the opportunity to insert your code at a certain point and do one or more of the following:
  1. Use echo to inject some HTML or other content into the response buffer,
  2. Modify global variable state for one or more variables, and/or
  3. Modify the parameters passed to your hook function (assuming the hook was called bydo_action_ref_array() instead of do_action() since the latter does not support passing variables by-reference.)

Filter Hooks

Filter Hooks behave very similar to Action Hooks but their intended use is to receive a value and potentially return a modified version of the value. A filter hook could also be used just like an Action Hook i.e. to modify a global variable or generate some HTML, assuming that's what you need to do when the hook is called. One thing that is very important about Filter Hooks that you don't need to worry about with Action Hooks is that the person using a Filter Hook must return (a modified version of) the first parameter it was passed. A common newbie mistake is to forget to return that value!

Using Additional Parameters to Provide Context in Filter Hooks

As an aside I felt that Filter Hooks were hobbled in earlier versions of WordPress because they would receive only one parameter; i.e they would get a value to modify but no 2nd or 3rd parameters to provide any context. Lately, and positively however, it seems the WordPress core team has joyously (for me) been adding extra parameters to Filter Hooks so that you can discover more context. A good example is the posts_where hook; I believe a few versions back it only accepted one parameter being the current query's "where" class SQL but now it accepts both the where clause and a reference to current instance of the WP_Query class that is invoking the hook.

So what's the Real Difference?

In reality Filter Hooks are pretty much a superset of Action Hooks. The former can do anything the latter can do and a bit more albeit the developer doesn't have the responsibility to return a value with the Action Hook that he or she does with the Filter Hook.

Giving Guidance and Telegraphing Intent

But that's probably not what is important. I think what is important is that by a developer choosing to use an Action Hook vs. a Filter Hook or vice versa they are telegraphing their intent and thus giving guidance to the themer or plugin developer who might be using the hook. In essence they are saying either "I'm going to call you, do whatever you need to do" OR"I've going to pass you this value to modify but be sure that you pass it back." 

Monday, July 29, 2013

how to run mail function in localhost php

do set in your php.ini file if you have any smtp configuration the do set nothing is requied to run email


SMTP = smtp.yoursmtp.com

smtp_port = 25
sendmail_from = bikash@htssgroups.com

Thursday, July 25, 2013

Change default from email -->wordpress@mydomain.com in wordpress

Change default email -->wordpress@mydomain.com to

 

 

step in 


If you wish to hard code this.. it's in wp-includes/pluggable.php
lines 320 and 336

Wednesday, July 24, 2013

joomla you have no access to this page The requested resource was not found. An error has occurred while processing your request.Eroor: 500 [Solve]

Hi new developers, i was spent lot of time lastly my own mind has resolved this issue.
that why  i do want to spend time any other resource in joomla.
for joomla administrator error
do change the configuration log and tmp path in configuration.php
--------------------------------------------------------------------------------------
set your server log path  like "d:\xampp\htdocs\projects/log"
same as tmp path                 "d:\xampp\htdocs\projects/tmp"
-------------------------------------------------------------------------------------


"an out-of-date bookmark/favourite     a search engine that has an out-of-date listing for this site     a mistyped address     you have no access to this page     The requested resource was not found.     An error has occurred while processing your request ERROR : 500 [solved] joomla.

thanks
Bikash ranjan

Friday, July 19, 2013

how to add custom menu in worpress menu van items


if($current_user->user_login == 'cloudburst') :
function add_login_out_item_to_menu( $items, $args ){
$link = '<li id="log-in-out-link" class="menu-item menu-type-link"><a href="'.get_bloginfo('url').'/allproducts">Shop</a></li>';
return $items.= $link;
}add_filter( 'wp_nav_menu_items', 'add_login_out_item_to_menu', 50, 2 );

endif;

Friday, July 12, 2013

how to check is availability domain using php curl

<?php
if (domainAvailibility('http://www.bikashsadf.com'))
       {
               echo "Up and running!";
       }
       else
       {
               echo "Woops, nothing found there.";
       }

       //returns boolean value
       function domainAvailibility($domain)
       {
               //check, if a valid url is provided
               if(!filter_var($domain, FILTER_VALIDATE_URL))
               {
                       return false;
               }

               //initialize curl
               $curlInit = curl_init($domain);
               curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10);
               curl_setopt($curlInit,CURLOPT_HEADER,true);
               curl_setopt($curlInit,CURLOPT_NOBODY,true);
               curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true);

               //get answer
               $response = curl_exec($curlInit);

               curl_close($curlInit);

               if ($response) return true;

               return false;
       }
?>

Saturday, July 6, 2013

how to keep a session alive for 30 minutes and then destroy it in php

session.gc_maxlifetime
session.gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage' and cleaned up. Garbage collection occurs during session start.
But the garbage collector is only started with a probability of session.gc_probability divided by session.gc_divisor. And using the default values for that options (1 and 100 respectively), the chance is only at 1%.
Well, you could argue to simply adjust these values so that the garbage collector is started more often. But when the garbage collector is started, it will check the validity for every registered session. And that is cost-intensive.
Furthermore, when using PHP’s default session save handler files, the session data is stored in files in a path specified in session.save_path. With that session handler the age of the session data is calculated on the file’s last modification date and not the last access date:
Note: If you are using the default file-based session handler, your filesystem must keep track of access times (atime). Windows FAT does not so you will have to come up with another way to handle garbage collecting your session if you are stuck with a FAT filesystem or any other filesystem where atime tracking is not available. Since PHP 4.2.3 it has used mtime (modified date) instead of atime. So, you won't have problems with filesystems where atime tracking is not available.
So it additionally might occur that a session data file is deleted while the session itself is still considered as valid because the session data was not updated recently.
And second:
session.cookie_lifetime
session.cookie_lifetime specifies the lifetime of the cookie in seconds which is sent to the browser. […]

Wordpress custom search post and contents and by author name from wp_posts, wp_postmeta,wp_term_relationships tables

my custom wordpress search functinality you can help by my code please follow my code

-----------------------------------------------------------------------------------------------------------
 <form action="?page_id=155" method="POST" name="myForm" onSubmit="return validateForm()">
 
 
   <div class="search">

   <input type="submit" class="src-img" value="" name="sub">
        <input  value="Search Title And Author" onFocus="if(this.value=='Search Title And Author') this.value='';" onBlur="if(this.value=='') this.value='Search Title And Author';" name="search" id="search" type="text" class="src" />
<select name="authornamesearch"  class="select-src">
<option value="0">Select Author</option>
<option value="Bikash ranjan">Bikash ranjan</option>
<option value="Snatosh nayak">Snatosh nayak</option>
<option value="Himansu swain">Himansu swain</option>
<option value="Amara behera">Amara behera</option>

</select>
<input type="submit" class="src-btn" value="Search" name="subsearch">
   
      </div>
</form>
------------------------------------------Search Request handler page-------------------------------------------
  <?php
$search =trim($_REQUEST['search']);
$getAuthor=trim($_REQUEST['authornamesearch']);
$searchcln=trim(mysql_real_escape_string($search));
$getAuthorln=trim(mysql_real_escape_string($getAuthor));
$uarr = array();

if(($search!='Search Title And Author')or($getAuthor!=''))
{

if(($search!='Search Title And Author')&&($getAuthor!="0"))
{
$where ="wpmt.meta_key = 'author_name' AND wpmt.meta_value ='$getAuthorln' and (wp.post_title LIKE '%$searchcln%' or wp.post_content like '%$searchcln%')
AND wp.post_type = 'post' AND wtr.term_taxonomy_id != '1' AND wp.post_status <> 'trash'";

}
else if(($search=='Search Title And Author')&&($getAuthor!="0"))
{

$where ="wpmt.meta_key = 'author_name' AND wpmt.meta_value LIKE '%$getAuthorln%' AND wp.post_type = 'post' AND wtr.term_taxonomy_id != '1' AND wp.post_status <> 'trash'";
}
else{
  $where ="(wp.post_content like '%$searchcln%' AND wp.post_status ='publish' AND wp.post_type='post' and wtr.term_taxonomy_id != '1' AND wp.post_status <> 'trash')
            or (wp.post_title LIKE '%$searchcln%' AND wp.post_status ='publish' AND wp.post_type='post' and wtr.term_taxonomy_id != '1' AND wp.post_status <> 'trash')
or(wpmt.meta_key='author_name' AND wpmt.meta_value like '%$searchcln%' AND wp.post_type='post' and wtr.term_taxonomy_id != '1' AND wp.post_status <> 'trash')";
    }

$sql_query="SELECT distinct wp.* FROM
                           wp_posts wp
    INNER JOIN                 wp_term_relationships wtr
ON                         wtr.object_id = wp.ID
INNER JOIN                 wp_postmeta wpmt
ON                         wpmt.post_id = wp.ID
WHERE $where";
//echo $sql_query;
$rs = @mysql_query($sql_query);
$numberOfRows = @mysql_num_rows($rs);
if($numberOfRows>=1)
{
$p=0;
while($row = @mysql_fetch_array($rs))
{
$uarr[$p]['ID'] = $row['ID'];
//$uarr[$p]['post_content'] = $row['post_content'];
$uarr[$p]['post_title'] = $row['post_title'];
//$uarr[$p]['post_name'] = $row['post_name'];
//$uarr[$p]['guid'] = $row['guid'];
$p++;
}
}else
{
$message= "<h2 style='color:red;'>Not found&nbsp;".$search."&nbsp; in our book`s categories</h2>";
}


}


?>


how to retrieve custom categories and post and author in wordpress

Hello my developers please include this class and call your function according to your requirement
<?php

class common_class {


public function  mainCagoryId(){
$parent = 0;
    $sql_query = "SELECT
   wt.term_id
FROM
wp_terms wt
INNER JOIN
wp_term_taxonomy wtt
ON

wt.term_id = wtt.term_id
WHERE
wtt.taxonomy = 'category' AND
wtt.parent = '".$parent."' AND
wt.name!= 'Uncategorized' order by RAND() limit 1

";

        $rs = @mysql_query($sql_query);
      $res=mysql_fetch_array($rs);
 return $res['term_id'];
}
 public function mainCategory()

 {
    $catArr = array();
$parent = 0;
    $sql_query = "SELECT
   wt.term_id, wt.name, wt.slug,
wtt.term_taxonomy_id, wtt.taxonomy, wtt.description, wtt.parent, wtt.count
FROM
wp_terms wt
INNER JOIN
wp_term_taxonomy wtt
ON

wt.term_id = wtt.term_id
WHERE
wtt.taxonomy = 'category' AND
wtt.parent = '".$parent."' AND
wt.name!= 'Uncategorized' order by wt.sort_item ASC

";

        $rs = @mysql_query($sql_query);
      if($rs && @mysql_num_rows($rs)>0)
     {
      $i=1;
      while($row = @mysql_fetch_array($rs))
      {

                     $catArr['term_id'][$i]           =        $row['term_id'];
 $catArr['name'][$i]              =        $row['name'];
 $catArr['slug'][$i]              =        $row['slug'];
 $catArr['term_taxonomy_id'][$i]  =        $row['term_taxonomy_id'];
 $catArr['taxonomy'][$i]          =        $row['taxonomy'];
 $catArr['description'][$i]       =        $row['description'];
                 
     $i=$i+1;

                 }
    }

return $catArr;
  }


      function getBook($catid)
   {
  $categoryId = $catid;
  $productArr= array();


  $sql_query = "SELECT
wp.ID, wp.post_title, wp.post_content, wp.guid, wp.post_name
FROM
wp_term_relationships wtr
INNER JOIN
wp_posts wp
ON
wtr.object_id = wp.ID



WHERE
wtr.term_taxonomy_id = '".$categoryId."' AND
wp.post_status != 'trash' order by wp.post_title asc
";


$rs = @mysql_query($sql_query);
if($rs && @mysql_num_rows($rs)>0)
{
   $i=1;
while($row = @mysql_fetch_array($rs))
      {

                     $productArr['ID'][$i]                =        $row['ID'];
 $productArr['post_title'][$i]        =        $row['post_title'];
 $productArr['post_content'][$i]      =        $row['post_content'];
 $productArr['post_name'][$i]         =        $row['post_name'];
               
     $i=$i+1;
                 }

     }
     
   return $productArr;

  }


   function getBookLimit($catid)
   {

   $categoryId = $catid;

 $productArr= array();




   $sql_query = "SELECT
distinct wp.ID, wp.post_title, wp.post_content, wp.guid, wp.post_name
FROM
wp_term_relationships wtr
INNER JOIN
wp_posts wp
ON
wtr.object_id = wp.ID



WHERE
wtr.term_taxonomy_id = '".$categoryId."' AND
wp.post_status != 'trash' order by wp.post_title asc limit 0,5

";
$rs = @mysql_query($sql_query);
if($rs && @mysql_num_rows($rs)>0)
{
   $i=1;
while($row = @mysql_fetch_array($rs))
      {

                     $productArr['ID'][$i]                =        $row['ID'];
 $productArr['post_title'][$i]        =        $row['post_title'];
 $productArr['post_content'][$i]      =        $row['post_content'];
 $productArr['post_name'][$i]         =        $row['post_name'];
               
     $i=$i+1;
                 }

     }
     
   return $productArr;

  }








  public function bestSellerCategory()

 {
       $bestSellerArr = array();
    $parent = 0;
      $sql_query = "SELECT
   wt.term_id, wt.name, wt.slug,
wtt.term_taxonomy_id, wtt.taxonomy, wtt.description, wtt.parent, wtt.count
FROM
wp_terms wt
INNER JOIN
wp_term_taxonomy wtt
ON

wt.term_id = wtt.term_id
WHERE
wtt.taxonomy = 'category' AND
wtt.parent = '".$parent."' AND
wt.name!= 'Uncategorized' order by RAND()

";
        $rs = @mysql_query($sql_query);
      if($rs && @mysql_num_rows($rs)>0)
     {
      $i=1;
      while($row = @mysql_fetch_array($rs))
      {

                     $bestSellerArr['term_id'][$i]           =        $row['term_id'];
 $bestSellerArr['name'][$i]              =        $row['name'];
 $bestSellerArr['slug'][$i]              =        $row['slug'];
 $bestSellerArr['term_taxonomy_id'][$i]  =        $row['term_taxonomy_id'];
 $bestSellerArr['taxonomy'][$i]          =        $row['taxonomy'];
 $bestSellerArr['description'][$i]       =        $row['description'];
                 
     $i=$i+1;

                 }
    }
return $bestSellerArr;
  }


     function bestSellerBook($catid)
   {

  $categoryId = $catid;

  $productArr= array();




  $sql_query = "SELECT
wp.ID, wp.post_title, wp.post_content, wp.guid, wp.post_name
FROM
wp_term_relationships wtr
INNER JOIN
wp_posts wp
ON
wtr.object_id = wp.ID



WHERE
wtr.term_taxonomy_id = '".$categoryId."' AND
wp.post_status != 'trash' order by wp.post_date_gmt desc limit 0,2

";
$rs = @mysql_query($sql_query);
if($rs && @mysql_num_rows($rs)>0)
{
   $i=1;
while($row = @mysql_fetch_array($rs))
      {

                     $productArr['ID'][$i]                =        $row['ID'];
 $productArr['post_title'][$i]        =        $row['post_title'];
 $productArr['post_content'][$i]      =        $row['post_content'];
 $productArr['post_name'][$i]         =        $row['post_name'];
               
     $i=$i+1;
                 }

     }
       

    return $productArr;

  }



   public function get_bookdetails($id)

 {
 
   $bookDetailsArr = array();
     $sql_query = "SELECT
   ID,post_content,post_title,guid
FROM
wp_posts



WHERE
ID  = '".$id."'

";
        $rs = @mysql_query($sql_query);
        if($rs && @mysql_num_rows($rs)>0)
       {
   
      while($row = @mysql_fetch_array($rs))
      {
                      $bookDetailsArr[1]       =        $row['ID'];
  $bookDetailsArr[2]       =        $row['post_title'];
  $bookDetailsArr[3]       =        $row['post_content'];
  $bookDetailsArr[4]       =        $row['guid'];
     }
    }

return $bookDetailsArr;
     }



public function get_category($catid)

 {
 
  $catArrr = array();
     $sql_query = "SELECT
   wt.term_id, wt.name,wtt.description,wtt.term_taxonomy_id
FROM
wp_terms wt
INNER JOIN
wp_term_taxonomy wtt
ON

wt.term_id = wtt.term_id
WHERE
wt.term_id = '".$catid."' AND wtt.taxonomy = 'category' and wt.name!= 'Uncategorized'  
";


        $rs = @mysql_query($sql_query);
        if($rs && @mysql_num_rows($rs)>0)
       {
   
      while($row = @mysql_fetch_array($rs))
      {
                      $catArrr[1]       =        $row['term_id'];
  $catArrr[2]       =        $row['name'];
  $catArrr[3]       =        $row['description'];
  $catArrr[4]       =        $row['term_taxonomy_id'];      

     }
    }

return $catArrr;
     }


  public function get_authorName($id)

        {
 
    $authorname = array();
      $sql_query = " SELECT
                    post_id , MAX( IF( meta_key = 'author_name', meta_value , NULL ) ) AS author
         
             FROM
                                wp_postmeta

                          WHERE post_id =".$id."
";
        $rs = @mysql_query($sql_query);
        if($rs && @mysql_num_rows($rs)>0)
       {
   
      while($row = @mysql_fetch_array($rs))
      {
                      $authorname[1]               =        $row['post_id'];
  $authorname[2]               =        $row['author'];

     }
    }

return $authorname;
     }



 public function get_pdfurl($id)

        {
 
    $pdfurl = array();
       $sql_query = " SELECT
                    post_id , MAX( IF( meta_key = 'pdf_url', meta_value , NULL ) ) AS PDFURL
       
         
             FROM
                                wp_postmeta

                          WHERE post_id =".$id."
";
        $rs = @mysql_query($sql_query);
        if($rs && @mysql_num_rows($rs)>0)
       {
   
      while($row = @mysql_fetch_array($rs))
      {
                      $pdfurl[1]               =        $row['post_id'];
  $pdfurl[2]               =        $row['PDFURL'];

     }
    }

return $pdfurl;
     }


function popularbook($catid)
   {

 $categoryId = $catid;

 $productArr= array();




  $sql_query = "SELECT
wp.ID, wp.post_title, wp.post_content, wp.guid, wp.post_name
FROM
wp_term_relationships wtr
INNER JOIN
wp_posts wp
ON
wtr.object_id = wp.ID



WHERE
wtr.term_taxonomy_id = '".$categoryId."' AND
wp.post_status != 'trash' order by wp.ID desc limit 0,20

";
$rs = @mysql_query($sql_query);
if($rs && @mysql_num_rows($rs)>0)
{
   $i=1;
while($row = @mysql_fetch_array($rs))
      {

                     $productArr['ID'][$i]                =        $row['ID'];
 $productArr['post_title'][$i]        =        $row['post_title'];
 $productArr['post_content'][$i]      =        $row['post_content'];
 $productArr['post_name'][$i]         =        $row['post_name'];                
     $i=$i+1;
                 }

     }
     
   return $productArr;

  }

function allCategorypopularbook($catid)
{

 $categoryId = $catid;

 $productArr= array();

  $sql_query = "SELECT
wp.ID, wp.post_title, wp.post_content, wp.guid, wp.post_name
FROM
wp_term_relationships wtr
INNER JOIN
wp_posts wp
ON
wtr.object_id = wp.ID



WHERE
wtr.term_taxonomy_id = '".$categoryId."' AND
wp.post_status != 'trash' order by wp.ID desc limit 0,5

";
$rs = @mysql_query($sql_query);
if($rs && @mysql_num_rows($rs)>0)
{
   $i=1;
while($row = @mysql_fetch_array($rs))
      {

                     $productArr['ID'][$i]                =        $row['ID'];
 $productArr['post_title'][$i]        =        $row['post_title'];
 $productArr['post_content'][$i]      =        $row['post_content'];
 $productArr['post_name'][$i]         =        $row['post_name'];
               
     $i=$i+1;
                 }

     }
     
   return $productArr;

  }












}
?>

Friday, July 5, 2013

how to write a program square x root of y. using function in php

<?php
function squarepow2($x,$y)
{
    (float)$total=1;
    for($i=1;$i<=$y;$i++)
   {
        $total*=$x;
    }
    return $total ;
}
echo squarepow2(2.0,3);
?>

Why does the session value get deleted after the user deletes browser cookies?

How can we keep session value when user cookies are deleted?
 <?php
    session_start();
  echo $_SESSION['userdata']['name']='bikash';
?>
If user deletes the cookies, my session value has deleted. Please advise.

Answers:

As other posters have mentioned the cookies contains the session id which is required to access the session. However unless you perform a session_destroy() the actual session data can be still found on the directory which session files are stored.

If you have some other means of assigning a previous session to a user, for example if you have a database that maps ip addresses to session ids (bad idea!), then you could restore the previous session id usingsession_id().

Wednesday, July 3, 2013

how to download large pdf file using php header function ?SOLVE ISSUE

<?php
if($filepath!=''){
header('Pragma: public');  // required
header('Expires: 0');  // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: application/pdf');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filepath)) . ' GMT');
header('Content-Disposition: attachment; filename=' . urlencode(basename($filepath)));
header("Content-Transfer-Encoding:  binary");
header('Content-Length: ' . filesize($filepath)); // provide file size
header('Connection: close');
ob_end_clean();
readfile($filepath);
exit();
}