PHP Developer

Wednesday, 20 June 2018

Rest API

$siteurl = site_url();
$baseuri = $siteurl."/wp-json";
$method = $request->get_method();
$body = $request->get_body();
$route = $request->get_route();
$params = json_encode($request->get_params());
$fullapiurl = $baseuri.$route;
$ctype = $request->get_content_type();
$contentType = isset($ctype)?$ctype['value']:'application/json';
$url = parse_url($siteurl);

$route == "/wc/v2/login";


//authenication method over http
            $oauthTimestamp = time();
            $nonce = md5(mt_rand());
            $oauthSignatureMethod = "HMAC-SHA1";
            $oauthVersion = "1.0";

            $sigBase = $method."&" . rawurlencode($fullapiurl) . "&"
                . rawurlencode("oauth_consumer_key=" . rawurlencode($consumer_key)
                . "&oauth_nonce=" . rawurlencode($nonce)
                . "&oauth_signature_method=" . rawurlencode($oauthSignatureMethod)
                . "&oauth_timestamp=" . $oauthTimestamp
                . "&oauth_version=" . $oauthVersion);

            $sigKey = $consumer_secret . "&";
            $oauthSig = base64_encode(hash_hmac("sha1", $sigBase, $sigKey, true));

            $requestUrl = $fullapiurl . "?"
                . "oauth_consumer_key=" . rawurlencode($consumer_key)
                . "&oauth_nonce=" . rawurlencode($nonce)
                . "&oauth_signature_method=" . rawurlencode($oauthSignatureMethod)
                . "&oauth_timestamp=" . rawurlencode($oauthTimestamp)
                . "&oauth_version=" . rawurlencode($oauthVersion)
                . "&oauth_signature=" . rawurlencode($oauthSig);

$ch = curl_init($requestUrl);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $httpMethod = strtolower($method);
    if($httpMethod == "post"){           
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $body);       
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                        'Content-Type: '.$contentType,
                       'Content-Length: ' . strlen($body))
         );
    }   
    else{
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);       
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                        'Content-Type: '.$contentType)
         );
    }
   
    $response = curl_exec($ch);
    if(curl_errno($ch)) {
      echo 'Curl error: ' . curl_error($ch);
    }
    curl_close($ch);

Sunday, 17 June 2018

Jquery get selected checkbox values

<input type="checkbox" name="vehicle" value="('a', 'b', 'c', 'd')">abcd<br>
<input type="checkbox" name="vehicle" value="('e', 'f', 'g', 'h')">efgh<br>
<input type="checkbox" name="vehicle" value="('i', 'j', 'k', 'l')">ijkl<br>
<input type="checkbox" name="vehicle" value="('m', 'n', 'o', 'p')">mnop<br>
<input type="checkbox" name="vehicle" value="('q', 'r', 's', 't')">qrst<br>
<input type="checkbox" name="vehicle" value="('u', 'v', 'w', 'x')">uvwx<br>
<input type="checkbox" name="vehicle" value="('y', 'z', '1', '2')">yz12<br>
<input type="button" value="Get values" id="get_values">

<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(document).on('click', '#get_values', function(){
var favorite = [];
$.each($("input[name='vehicle']:checked"), function(){           
favorite.push($(this).val());
$(this).append('Saved');
$( "<span>Saved</span>" ).insertAfter( this );
$(this).remove();
});
if(favorite.length > 0){
alert(favorite.join(", "));
}else{
alert("Select atleast one value from list.");
}
//alert("My favourite sports are: " + favorite.join(", "));
});
</script>

Thursday, 14 June 2018

Login

Link : https://drive.google.com/file/d/1VOrOUF97scv7qCf9PVqH4E4GhfJfgqmC/view?usp=sharing

Sunday, 10 June 2018

DataTable

https://drive.google.com/file/d/1nCY186V4uG7QFBWzrHmG-R555q9JK0GZ/view?usp=sharing

Wednesday, 14 March 2018

Sticky Header

https://codepen.io/jovanivezic/pen/ZQNdag
http://jsfiddle.net/0mLzseby/473/
http://jsfiddle.net/FDv2J/1913/
https://codepen.io/perminder-klair/pen/tdzue

Tuesday, 30 January 2018

Cash Back Plugin

https://drive.google.com/open?id=1fH0mmtCxUHYB9EpZIDmjyMU1UeJYhR6A

Thursday, 16 November 2017

Create custom carousel slider with custom post type using Slick slider library

Create custom carousel slider with custom post type using Slick slider library



<!------- Create Custom post Type Crousel Slider Using Slick Slider ---------->
<?php
$team_slider_html = '';

$args = array(
    'post_type' => 'product',
    'post_status' => 'publish',
    'posts_per_page' => 10,
);
$query = new WP_Query( $args );
$team_slider_html .= '<section class="center slider hometeam_slider">';
while ( $query->have_posts() ) : $query->the_post();
    if (has_post_thumbnail( get_the_ID() ) ){
        $image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'single-post-thumbnail' );
        $featured_image = $image[0];
    }else{
        $featured_image = site_url().'/wp-content/uploads/2017/10/report-covers.png';
    }
    $team_slider_html .= '<div class="single_team_slide"><div class="single_slide_inner">';
    $team_slider_html .= '<div class="team_member_image"><img src="'.$featured_image.'"></div>';
    $team_slider_html .= '<div class="team_member_excerpt">'.get_the_excerpt().'</div>';
    $team_slider_html .= '<div class="team_member_name">'.get_the_title().'</div>';
    $team_slider_html .= '<div class="team_member_designation">'.get_post_meta( get_the_ID(), '_position', true ).'</div>';
    $team_slider_html .= '</div></div>';
endwhile;
$team_slider_html .= '</section>';

echo $team_slider_html;
?>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick.min.css'>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick-theme.min.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick.min.js'></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
jQuery(document).on('ready', function() {
    jQuery(".center").slick({
        dots: true,
        infinite: true,
        centerMode: true,
        autoplay: true,
        arrows: true,
        slidesToShow: 3,
        slidesToScroll: 1
    });
});
</script>