Wednesday, March 23, 2016

Wordpress- How to Create Custom Controls for the WordPress Theme Customizer

If we want to add textarea under Theme Customizer, we use the below code.

Put the below code in function.php

/*Customizer1 Code HERE*/
add_action('customize_register', 'theme_bannertext1_customizer' , 11);
function theme_bannertext1_customizer($wp_customize){
 //adding section in wordpress customizer  
    $wp_customize->add_section('banne1_settings_section', array(
      'title'          => 'Banner Text 1'
     ));
    //adding setting for footer text area
    $wp_customize->add_setting('banne1_settings_section', array(
     'default'        => 'Modern Axure template for Beautiful prototypes',
     ));
    $wp_customize->add_control('banne1_settings_section', array(
     'label'   => 'Banner Text1 Here',
      'section' => 'banne1_settings_section',
     'type'    => 'textarea',
    ));

 }

 /*Customizer2 Code HERE*/
add_action('customize_register', 'theme_bannertext2_customizer' , 12);
function theme_bannertext2_customizer($wp_customize){
 //adding section in wordpress customizer  
    $wp_customize->add_section('banne2_settings_section', array(
      'title'          => 'Banner Text 2'
     ));
    //adding setting for footer text area
    $wp_customize->add_setting('banne2_settings_section', array(
     'default'        => 'Modern Axure template for Beautiful prototypes',
     ));
    $wp_customize->add_control('banne2_settings_section', array(
     'label'   => 'Banner Text1 Here',
      'section' => 'banne2_settings_section',
     'type'    => 'textarea',
    ));

 }

Tuesday, March 22, 2016

Wordpress- Create Database Tables When on plugin actication hook

//create table               
function creat_table_on_actvation() {
         global $wpdb;
        $your_table_name = $wpdb->prefix . 'custom_contact_us';
     
        $sql = "CREATE TABLE IF NOT EXISTS " . $your_table_name . " (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `contact_name` varchar(255) NOT NULL,
          `contact_email` varchar(255) NOT NULL,
          `contact_subject` varchar(255) NOT NULL,
          `contact_message` text NOT NULL,
          `status` int(11) NOT NULL,
          `date_time` datetime NOT NULL,
          PRIMARY KEY (`id`)
        )";
        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
        dbDelta($sql);
}
// run the install scripts upon plugin activation
register_activation_hook(__FILE__,'creat_table_on_actvation');

PayPal - Adaptive Chained Payments

<?php

class PaypalTest {

public $api_user = "XXXXXXXXXXXXXXXXXXXXXX";
public $api_pass = "XXXXXXXXXXXXXXXXX";
public $api_sig = "XXXXXXXXXXXXXXXXXXXXXXX";
public $app_id = "APP-80W284485P519543T";
public $apiUrl = 'https://svcs.sandbox.paypal.com/AdaptivePayments/';
//public $paypalUrl="https://www.paypal.com/webscr?cmd=_ap-payment&paykey=";
public $paypalUrl="https://sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=";
public $headers;

public function __construct(){
    $this->headers = array(
        "X-PAYPAL-SECURITY-USERID: ".$this->api_user,
        "X-PAYPAL-SECURITY-PASSWORD: ".$this->api_pass,
        "X-PAYPAL-SECURITY-SIGNATURE: ".$this->api_sig,
        "X-PAYPAL-REQUEST-DATA-FORMAT: JSON",
        "X-PAYPAL-RESPONSE-DATA-FORMAT: JSON",
        "X-PAYPAL-APPLICATION-ID: ".$this->app_id,
    );
  
    $this->envelope= array(
            "errorLanguage" => "en_US",
            "detailLevel" => "ReturnAll",
        );
  
  
}

public function getPaymentOptions($paykey){

//echo $paykey; die;
   $packet = array(
          "requestEnvelope" => $this->envelope ,
          "payKey" => $paykey
   );
 
   return $this->_paypalSend( $packet ,'GetPaymentOptions');
}

public function _paypalSend($data,$call){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $this->apiUrl.$call);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
    $response = json_decode(curl_exec($ch),true);
    return $response;

}

public function splitPay(){


    // create the pay request
    $createPacket = array(
        "actionType" =>"PAY_PRIMARY",
        "applicationId" =>"APP-80W284485P519543T",
        "currencyCode" => "USD",
        "receiverList" => array(
            "receiver" => array(
               array(
                    "amount"=> "7.00",
                    "primary" => true,
                    "email"=>"primary-reciever@gmail.com"
                ),
                array(
                    "amount"=> "3.00",
                    "primary" => false,
                    "email"=>"secondary-reciever@gmail.com"
                ),
            ),
        ),
        "returnUrl" => "http://your-site-url/confirm.php",
        "cancelUrl" => "http://your-site-url//cancel.php",
        "requestEnvelope" => $this->envelope
    );

    $response = $this->_paypalSend($createPacket,"Pay");
  
  
    
    $paykey =  $response['payKey'];
    //echo '9999<pre>'; print_r($response);
  
    //SET payment details
  
     $detailsPacket=array(
"requestEnvelope" =>$this->envelope,
"payKey" => $paykey,
"receiverOptions" => array(
    array(
    "receiver" => array("email" => "primary-reciever@gmail.com"),
            "invoiceData" => array(
                "item" => array(
                    array(
                        "name" => "product1",
                        "price" => "7.00",
                        "identifier" => "p1"
                    ),
                   )
            )
    ),
    array(
        "receiver" => array("email" => 'secondary-reciever@gmail.com'),
        "invoiceData" => array(
        "item" => array(
            array(
                "name" => "product1",
                "price" => "3.00",
                "identifier" => "p1"
            ),
        )
      )
    ),
)
);


    $response1 = $this->_paypalSend($detailsPacket,"SetPaymentOptions");
  
  
    //$dets= $this->getPaymentOptions($paykey);
    $dets= $this->getPaymentOptions($paykey);
  
  

    $msg = $paykey;
  
    mail("amu02.aftab@gmail.com","My subject",$msg);
    //echo $this->paypalUrl.$paykey; die;
    header("Location: ".$this->paypalUrl.$paykey);
}

    public function _paymentExecute($url, $data){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
        $response = json_decode(curl_exec($ch),true);
        return $response;
    }

}


if($_GET['exe_pay'] == 1){
  
    $url = "https://svcs.sandbox.paypal.com/AdaptivePayments/ExecutePayment";
  
    $payment = new PaypalTest();
    
    $packet = array(
          "requestEnvelope" => $payment->envelope,
          "payKey" => "AP-96831732KV5898725"
   );
    $response = $payment->_paymentExecute($url, $packet);
    echo '<pre>';print_r($response);
}elseif($_GET['get_info'] == 1){
    $url = "https://svcs.sandbox.paypal.com/AdaptivePayments/PaymentDetails";
  
    $payment = new PaypalTest();
  
    $packet = array(
          "requestEnvelope" => $payment->envelope,
          "payKey" => "AP-96831732KV5898725"
   );
    $response = $payment->_paymentExecute($url, $packet);
    echo '<pre>';print_r($response);
}else{
      
      
    $payment = new PaypalTest();
    $payment->splitPay();
  
}?>

PayPal - Adaptive parallel Payments

<?php
class PaypalTest {

public $api_user = "XXXXXXXXXXXXXXXXXXXXXXXXXXX";
public $api_pass = "XXXXXXXXXXXXXXXXXXXX";
public $api_sig = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
public $app_id = "APP-80W284485P519543T";
public $apiUrl = 'https://svcs.sandbox.paypal.com/AdaptivePayments/';
//public $paypalUrl="https://www.paypal.com/webscr?cmd=_ap-payment&paykey=";
public $paypalUrl="https://sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=";
public $headers;

public function __construct(){
    $this->headers = array(
        "X-PAYPAL-SECURITY-USERID: ".$this->api_user,
        "X-PAYPAL-SECURITY-PASSWORD: ".$this->api_pass,
        "X-PAYPAL-SECURITY-SIGNATURE: ".$this->api_sig,
        "X-PAYPAL-REQUEST-DATA-FORMAT: JSON",
        "X-PAYPAL-RESPONSE-DATA-FORMAT: JSON",
        "X-PAYPAL-APPLICATION-ID: ".$this->app_id,
    );
    $this->envelope= array(
            "errorLanguage" => "en_US",
            "detailLevel" => "ReturnAll",
        );
}

public function getPaymentOptions($paykey){

   $packet = array(
          "requestEnvelope" => $this->envelope ,
          "payKey" => $paykey
   );
  
   return $this->_paypalSend( $packet ,'GetPaymentOptions');
}

public function _paypalSend($data,$call){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $this->apiUrl.$call);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
    $response = json_decode(curl_exec($ch),true);
    return $response;

}
public function splitPay(){
    // create the pay request
    $createPacket = array(
        "actionType" =>"PAY",
        "currencyCode" => "USD",
        "receiverList" => array(
            "receiver" => array(
               array(
                    "amount"=> "2.00",
                    "email"=>"First Reciever Email"
                ),
                array(
                    "amount"=> "2.00",
                    "email"=>"Second Reciever Email"
                ),
            ),
        ),
        "returnUrl" => "http://your-site/confirm.php",
        "cancelUrl" => "http://your-site/cancel.php",
        "requestEnvelope" => $this->envelope
    );

    $response = $this->_paypalSend($createPacket,"Pay");
    $paykey =  $response['payKey'];
    //SET payment details
   
     $detailsPacket=array(
"requestEnvelope" =>$this->envelope,
"payKey" => $paykey,
"receiverOptions" => array(
    array(
    "receiver" => array("email" => "First Reciever Email"),
            "invoiceData" => array(
                "item" => array(
                    array(
                        "name" => "product1",
                        "price" => "2.00",
                        "identifier" => "p1"
                    ),
                   )
            )
    ),
    array(
        "receiver" => array("email" => 'Second Reciever Email'),
        "invoiceData" => array(
        "item" => array(
            array(
                "name" => "product1",
                "price" => "2.00",
                "identifier" => "p1"
            ),
        )
      )
    ),
)
);


    $response = $this->_paypalSend($detailsPacket,"SetPaymentOptions");
    $dets= $this->getPaymentOptions($paykey);
   
   
      header("Location: ".$this->paypalUrl.$paykey);
}
}


$payment = new PaypalTest();
$payment->splitPay();

?>

Friday, March 18, 2016

WORDPRESS- Replacing a textarea with WordPress TinyMCE wp_editor()

WORDPRESS- Replacing a textarea with WordPress TinyMCE wp_editor()

$content= 'default content';
$editor_id ='textarea_id';
$settings = array( 'textarea_name' => 'post_text' );
wp_editor( $content, $editor_id, $settings );

Monday, March 14, 2016

Magento- Custom RWD default magento slider

Magento- Custom RWD default magento slider


<?php   $dynemicid = 1?>
                 <div class="class-toPopup" id="toPopup_<?php echo $dynemicid;?>" >
         
                <div class="slider-background">
                    <div class="slideshow-container-pop<?php echo $dynemicid;?>">
                        <ul class="slideshow">
                        <li><a href="javascript:void(0);"><img alt="" src="PUT IMAGE URL HRE" /> </a></li>
                        <li><a href="javascript:void(0);"><img alt="" src="PUT IMAGE URL HRE" /> </a></li>
                        <li><a href="javascript:void(0);"><img alt="" src="PUT IMAGE URL HRE" /> </a></li>
                        <li><a href="javascript:void(0);"><img alt="" src="PUT IMAGE URL HRE" /> </a></li>
                        <li><a href="javascript:void(0);"><img alt="" src="PUT IMAGE URL HRE" /> </a></li>
                        <li><a href="javascript:void(0);"><img alt="" src="PUT IMAGE URL HRE" /> </a></li>
                        <li><a href="javascript:void(0);"><img alt="" src="PUT IMAGE URL HRE" /> </a></li>
                        <li><a href="javascript:void(0);"><img alt="" src="PUT IMAGE URL HRE" /> </a></li>
                        <li><a href="javascript:void(0);"><img alt="" src="PUT IMAGE URL HRE" /> </a></li>
                       
                        </ul>
                    <div class="slideshow-pager<?php echo $dynemicid;?>">&nbsp;</div>
                    <span class="slideshow-prev">Previous</span>
                    <span class="slideshow-next">Next</span>
                    </div>
                </div>
              
                </div>
              
                <style>
                .slideshow-pager<?php echo $dynemicid;?> {
                    -moz-user-select: none;
                    overflow-x: hidden;
                    overflow-y: hidden;
                    position: absolute;
                    text-align: center;
                    top: auto;
                    width: 100%;
                    z-index: 115;
                }
                .slideshow-pager<?php echo $dynemicid;?> span {
                 color: #dddddd;
                    cursor: pointer;
                    display: inline-block;
                    font-family: "Roboto",sans-serif;
                    height: 10px;
                    width: 10px;
                }
                .slideshow-pager<?php echo $dynemicid;?> span:before {
                 background-color: #ccc;
                    border-radius: 10px;
                    content: "";
                    display: block !important;
                    height: 8px;
                    left: 50%;
                    margin-left: -8px;
                    margin-top: -8px;
                    position: relative;
                    top: 50%;
                    width: 8px;
                }
                .slideshow-pager<?php echo $dynemicid;?> span:hover:before {
                  background-color: #fff;
                  border:1px #999 solid;
                }
                .slideshow-pager<?php echo $dynemicid;?> span.cycle-pager-active:before {
                  background-color: #fff;
                  border:1px #999 solid;
                }
                .slideshow-pager<?php echo $dynemicid;?> > * {
                  cursor: pointer;
                }
      
                </style>
              
            <script>          

            $j(document).ready(function () {
          
                 $j('.slideshow-container-pop<?php echo $dynemicid;?> .slideshow').cycle({
                    slides: '> li',
                    pager: '.slideshow-pager<?php echo $dynemicid;?>',
                    pagerTemplate: '<span class="pager-box"></span>',
                    speed: 600,
                    pauseOnHover: true,
                    swipe: true,
                    prev: '.slideshow-prev',
                    next: '.slideshow-next',
                    fx: 'scrollHorz',
                    timeout: 0
                });  
        });
        </script>  
        <!--popup slide-->

Wednesday, March 9, 2016

PHP- check if image exists php

if (getimagesize($user_profilr_pic_url) !== false) {
                echo 'Image Exist';
            }else{
                 echo 'Image Does Not Exist';
            }