Ribbon Css

<div class="ribbon-wrap">
    <div class="ribbon">
        Ribbon Text
    </div>
</div>
.ribbon-wrap {
    background: #809E9B;
    height: 180px;
    margin: auto;
    overflow: hidden;
    position: relative;
    top: 0;
    width: 251px;
}
.ribbon-wrap .ribbon {
    background-color: #ABD065;
    background-image: linear-gradient(to bottom, #BFDC7A, #8EBF45);
    background-repeat: repeat-x;
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
    color: #4B4B4B;
    font-size: 12px;
    font-weight: bold;
    left: -69px;
    padding: 4px 0;
    position: relative;
    text-align: center;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
    top: 57px;
    transform: rotate(-47deg);
    width: 251px;
}

 

Paypal Payment Gateway For WordPress

Paypal payment gateway processing steps are

  1. Send data form your website to paypal
  2. Paypal process your data and return payment information
  3. Send again payment information to paypal for IPN validation
  4. Paypal again return IPN validated status, if status true then insert payment informationin in your database

Step1: Send data form your website to paypal

Sending data arguments are
$paypal_args = array(
    'cmd' => '_xclick',
    'amount' => 50,
    'business' => 'your paypal email. User will be payment this account',
    'item_name' => 'test',
    'item_number' => 20,
    'email' => 'payer email. who is send money to your business account',
    'no_shipping' => '1',
    'no_note' => '1',
    'currency_code' => 'USD',
    'charset' => 'UTF-8',
    'custom' => json_encode( array( 'user_id' => 1, 'product_id' => 20 ) ),
    'rm' => '2',
    'return' => 'www.example.com/paypal.php',
    'notify_url' => 'www.example.com/success_message',
    'cbt' => sprintf( __( 'Click here to complete the payment on %s', 'wpuf' ), get_bloginfo( 'name' ) )
);

//paypal url
if( sandbox ) {
    $paypal_url = 'https://www.sandbox.paypal.com/webscr/';
} else {
    $paypal_url = 'https://www.paypal.com/webscr/';
}

$paypal_url = $paypal_url . '?' . http_build_query( $paypal_args );

wp_redirect( $paypal_url );<br>exit;

 

Step2: Paypal process your data and return payment information
Step3: Send again payment information to paypal for IPN validation

www.example.com/paypal.php

 // Get recieved values from post data
$ipn_data = (array) stripslashes_deep( $_POST );
$ipn_data['cmd'] = '_notify-validate';

// Send back post vars to paypal
$params = array(
    'body' => $ipn_data,
    'sslverify' => false,
    'timeout' => 30,
    'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
);

//paypal url
if( sandbox ) {
    $paypal_url = 'https://www.sandbox.paypal.com/webscr/';
} else {
    $paypal_url = 'https://www.paypal.com/webscr/';
}

$response = wp_remote_post( $paypal_url, $params );

//Step4: Paypal again return IPN validated status, if status true then //insert payment informationin in your database

if ( !is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && (strcmp( $response['body'], "VERIFIED" ) == 0) ) {
    return true;
} else {
    return false;
}

 

 

Paypal Payment Gateway

Paypal payment gateway processing steps are

  1. Send data form your website to paypal
  2. Paypal process your data and return payment information
  3. Send again payment information to paypal for IPN validation
  4. Paypal again return IPN validated status, if status true then insert payment informationin in your database

Step1: Send data form your website to paypal

Sending data arguments are
$paypal_args = array(
    'cmd' => '_xclick',
    'amount' => 50,
    'business' => 'your paypal email. User will be payment this account',
    'item_name' => 'test',
    'item_number' => 20,
    'email' => 'payer email. who is send money to your business account',
    'no_shipping' => '1',
    'no_note' => '1',
    'currency_code' => 'USD',
    'charset' => 'UTF-8',
    'custom' => json_encode( array( 'user_id' => 1, 'product_id' => 20 ) ),
    'rm' => '2',
    'return' => 'www.example.com/paypal.php',
    'notify_url' => 'www.example.com/success_message',
    'cbt' => 'your blog name'
);

//paypal url
if( sandbox ) {
    $paypal_url = 'https://www.sandbox.paypal.com/webscr/';
} else {
    $paypal_url = 'https://www.paypal.com/webscr/';
}

$paypal_url = $paypal_url . '?' . http_build_query( $paypal_args );

header( "location:$paypal_url" );
 Step2: Paypal process your data and return payment information
Step3: Send again payment information to paypal for IPN validation

www.example.com/paypal.php

// Get recieved values from paypal post data
foreach( $_POST as $key => $value ) { 
   $params[$key] = stripslashes( $value ); 
}
$params = http_build_query( $params, null, '&' );

//paypal url
if( sandbox ) {
    $paypal_url = 'https://www.sandbox.paypal.com/webscr/';
} else {
    $paypal_url = 'https://www.paypal.com/webscr/';
}

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $paypal_url);
curl_setopt($ch,CURLOPT_POST, count($params));
curl_setopt($ch,CURLOPT_POSTFIELDS, $params);

//execute post
$response = curl_exec($ch);

//close connection
curl_close($ch);

//Step4: Paypal again return IPN validated status, if status true then insert payment informationin in your database

if ( $response == 'ok' && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && (strcmp( $response['body'], "VERIFIED" ) == 0) ) {
    echo 'Payment successfully you may insert payment information in your database';
} else {
    echo 'Error';
}

 Remember, IPN validation in your localhost always return false. You have to test IPN validation in your server site.

WordPress File Upload Process

This function has created for wordpress file uploading . You can easily upload your file with the help of this function.

function file_upload() {
    $upload = array(
        'name' => $_FILES['file']['name'],
        'type' => $_FILES['file']['type'],
        'tmp_name' => $_FILES['file']['tmp_name'],
        'error' => $_FILES['file']['error'],
        'size' => $_FILES['file']['size']
    );

    header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );

    $attach = handle_upload( $upload );

    if ( $attach['success'] ) {
        echo 'Successfully upload your file';
    } else {
        echo 'Fail to upload your file';
    }
}
function handle_upload( $upload_data ) {

    if ( ! function_exists( 'wp_handle_upload' ) ) {
       require_once( ABSPATH . 'wp-admin/includes/file.php' );
    }

    $uploaded_file = wp_handle_upload( $upload_data, array('test_form' => false) );

    if ( isset( $uploaded_file['file'] ) ) {
        $file_loc = $uploaded_file['file'];
        $file_name = basename( $upload_data['name'] );
        $file_type = wp_check_filetype( $file_name );
        $post_title = preg_replace( '/\.[^.]+$/', '', basename( $file_name ) );

        $attachment = array(
            'post_mime_type' => $file_type['type'],
            'post_title' => $post_title,
            'post_content' => '',
            'post_status' => 'inherit'
        );

        include( ABSPATH . 'wp-admin/includes/image.php' );
        $attach_id = wp_insert_attachment( $attachment, $file_loc );
        $attach_data = wp_generate_attachment_metadata( $attach_id, $file_loc );
        wp_update_attachment_metadata( $attach_id, $attach_data );
        return array('success' => true, 'attach_id' => $attach_id);
    }

    return array('success' => false, 'error' => $uploaded_file['error']);
}

 

WordPress Email Sending Configuration

WordPress email sending configuration for Bcc (Blind carbon copy).  If you want to send Cc (carbon copy) then change the first line as

$type = 'Cc: User <user@example.com>, Another User <anotheruser@example.com>';

Does not use to Bcc or Cc then remove the first line as

$type = 'Bcc: User <user@example.com>, Another User <anotheruser@example.com>';

here if full code

$type = 'Bcc: User <user@example.com>, Another User <anotheruser@example.com>';
$admin_email = get_option( 'admin_email' );
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
$reply = 'no-reply@' . preg_replace( '#^www\.#', '', strtolower( $_SERVER['SERVER_NAME'] ) );
$reply_to = "Reply_To: <$reply>";
$content_type = 'Content-Type: text/html';
$charset = 'Charset: UTF-8';
$from = "From: $blogname <$reply>";
$subject = 'test';
$message = 'Hi, how are you?';

$headers = array(
    $type,
    $reply_to,
    $content_type,
    $charset,
    $from
);
wp_mai( $admin_email, $subject, $message, $headers);

 

PHP autoload

PHP Autoload Usage:

Suppose you have a lot of php file in “my-class” directory. Each file contain php class. You want to call those class from other php file which is out of “my-class” directory. In this case the better way to use php autoload.

function autoload( $class ) {
    $directorys = array();

    //assing your php file directory which file containg your class
    $directorys = array(
        dirname(__FILE__) . '/your-class-directory',
    );

    if( ! count( $directorys ) ) {
        return;
    } 

    foreach( $directorys as $directory ) {

        if( ! is_dir( $directory ) ) {
            echo $directory .' Direcotry is not exist';
            continue;
        }

        if ( ! ( $handle = opendir( $directory ) ) ) {
            echo 'Fail to open your directory. Please check your directory permission';
            continue;
        }

        while ( false !== ( $entry = readdir( $handle ) ) ) {

            if ( $entry != "." && $entry != "..") {

                $file = $directory .'/'. $entry;
                $contents = file_get_contents( $file );
                $contents = str_replace( ' ', '', $contents ); 
                $contents = strtolower( $contents );
                $search = 'class'.$class.'{';

                if ( strpos( $contents, $search ) !== false ) {
                    require_once $directory .'/'. $entry;
                }
            }   
        }
        closedir( $handle );  
    }    
}

spl_autoload_register( 'autoload' );

 


Fatal error: Call to undefined function wp_pagenavi() in /home/mishubd/public_html/wp-content/themes/twentyfourteenchild/archive.php on line 45