Wednesday, December 18, 2013

WP Hit Counter Wordpress Plugin:-Function which helps you to show counter anywhere in template file

WP Hit Counter

Function which helps you to show counter anywhere in template file
paste the funtion any where and show this counter anywhere.
<?php echo HitCounter::display();?>

You will be able to create a shortcode with this function
  • Navigate to your plugins folder > wordpress-hit-counter
  • Open image.php and add the following function right before the ?> close: 
  •      add_shortcode( 'WP-Hit-Counter',HitCounter::display());

      Save your file

    Friday, August 30, 2013

    User-Access-Manager wordpress plugin sort field at user.php in admin

    Whe we use this plugin if we have many user registered in site and feel dificult to find the new user who are not a member yet,if you add the code below you will be able to see the "unauthorised users' by clicking at the "uam user groups"
    Added the following code below the file "user-access-manager.php" in your plugin folder.

    function user_sortable_columns( $columns) {

        $columns['uam_access'] =array( 'uam_access', 'desc' );
        return $columns;
    }
    add_filter( 'manage_users_sortable_columns', 'user_sortable_columns' );

    function user_column_orderby( $vars ) {
        if ( isset( $vars['orderby'] ) && 'uam_access' == $vars['orderby'] ) {

            $vars = array_merge( $vars, array(
                'meta_key' => 'uam_access',
                'orderby' => 'meta_value'

                   ) );


        }
        return $vars;
    }
    add_filter( 'request', 'user_column_orderby' );

    add_action('pre_user_query', 'status_order_in_user_query');

    function status_order_in_user_query($query){

    // print_r($query); // for debugging

    if('uam_access'==$query->query_vars['orderby'] && 'DESC'==$query->query_vars['order']) {

       $query->query_where .= " and id NOT IN (SELECT object_id FROM wp_uam_accessgroup_to_object
    WHERE object_type = 'user')";

    }

    }

    Tuesday, June 25, 2013

    Simple PHP Pagination

    Download this file
    https://docs.google.com/file/d/0B-WSEGv0VCtJYXRRQkRIVlFpNEE/edit?usp=sharing

    Make this as pagination.php and include to your php file

     <?php include("pagination.php");
                echo pagination(20, $page, 'mypage.php?page=', $count);
    ?>
    In mypage.php you should use the sql query according to pagination
    <?php
    $query="select * from table "
    if (isset($_GET['page'])) {
            $start = ($_GET['page'] - 1) * 20;
           $query.=" limit $start,20";
         

        } else {
    $query.=" limit 20";
         
        }
    $result=mysql_fetch_array(mysql_query($query));
    ?>

    Download any file with php using header

    You can download any file using this
    Step1:Copy the code to a page called download.php(note:dont need any html tags should only contains this code)
    Step2:Create a link with your file name
    <a href="download.php?filename=myfile.jpg">Download</a> in your page(not at download page)


    <?php
     //BUILD THE FILE INFORMATION
         $file = $_REQUEST['filename'];

         //CREATE/OUTPUT THE HEADER
         header("Content-type: application/force-download");
         header("Content-Transfer-Encoding: Binary");
         header("Content-length: ".filesize($file));
         header("Content-disposition: attachment; filename=\"".basename($file)."\"");
         readfile($file);
    ?>

    Find total time using mysql query when you have two datetime fields

    SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(date_out,date_in)))) as total FROM mytable


    Also you can find this using php

    function sum_the_time($time1, $time2) {
      $times = array($time1, $time2);
      $seconds = 0;
      foreach ($times as $time)
      {
        list($hour,$minute,$second) = explode(':', $time);
        $seconds += $hour*3600;
        $seconds += $minute*60;
        $seconds += $second;
      }
      $hours = floor($seconds/3600);
      $seconds -= $hours*3600;
      $minutes  = floor($seconds/60);
      $seconds -= $minutes*60;
      // return "{$hours}:{$minutes}:{$seconds}";
      return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
    }

    function diff_the_time($time1, $time2) {
     $seconds=strtotime($time1)-strtotime($time2);
      $hours = floor($seconds/3600);
      $seconds -= $hours*3600;
      $minutes  = floor($seconds/60);
      $seconds -= $minutes*60;
      // return "{$hours}:{$minutes}:{$seconds}";
      return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
    }