Paypal Integration in php

1. Make a new folder in your localhost and Save this file index.php 

<?php
$paypal_username = "arunendra123-facilitator_api1.smartwinzsolutions.com";
$paypal_password = "1394441";
$paypal_signature = "A05YM4frUDrScsYqP299BBa4trgEA3InSTImhusSPEE8pKNdBzC";
include("paypal_pro_signature.inc.php");

$firstName = urlencode("arunbuyer");
$lastName = urlencode("rai");
$creditCardType = urlencode("Visa");
$creditCardNumber = urlencode("4271901174400127");
$expDateMonth = urlencode("03");
$padDateMonth = str_pad($expDateMonth,2,'0',STR_PAD_LEFT);
$expDateYear = urlencode("2019");
$cvv2Number = urlencode("123");
$address1 = urlencode("test");
$address2 = urlencode("test");
$city = urlencode("test");
$state = urlencode("test");
$zip = urlencode("73301");
$amount = urlencode("25.75");
$currencyCode = urlencode("USD");
$paymentAction = urlencode("Sale");
$methodToCall = 'DoDirectPayment';

Show Different Number Of Posts Per Category In WordPress

WPRecipes has posted a way to set different number of posts for a WordPress category. It works nicely, but only for one category. And it uses custom query, which is not very familiar to newbies. In this post, we’ll do the same thing more simpler.

Assume that we want to show 5 posts per page for category “WordPress” and 10 posts per page for category “song”, just open the functions.php file in your theme folder and insert these line into it:

1.  add_action('pre_get_posts', 'diff_post_count_per_cat');
2.   
3.  function diff_post_count_per_cat() {
4.      if (is_admin()) return;
5.   
6.      $cat = get_query_var('category_name');
7.      switch ($cat) {
8.          case 'wordpress':
9.              set_query_var('posts_per_page', 5);
10.            break;
11.        case 'wordpress/song':
12.            set_query_var('posts_per_page', 2);
13.            break;   
14.    }
15.}

Change “wordpress” and “song” into real category names of your blog. Note that in the code above, we use category slug, not original name. If the category is a child category, don’t forget to insert full path (i.e. “wordpress/song” in the example below).


Change WordPress Default Email From Name And Address

By default, WordPress uses the from name “WordPress” and address “wordpress@yourdomain.com” when it sends notifications to users. It isn’t convenient and you might want to change it into your Blog name or something like that. This tutorial will show you how to do this just with some simple code.

Open the functions.php file of your theme and paste the following code into it:
  1. add_filter('wp_mail_from', 'new_mail_from');
  2. add_filter('wp_mail_from_name', 'new_mail_from_name');
  3.  
  4. function new_mail_from($old) {
  5. return 'admin@yourdomain.com';
  6. }
  7. function new_mail_from_name($old) {
  8. return 'Your Blog Name';
  9. }

Displaying A Login Form In Sidebar

Displaying A Login Form In Sidebar In WordPress

In WordPress 2.x and ealier, to display a login form in sidebar, we must use some raw PHP codes. But since version 3.0, WordPress provides new function, wp_login_form(), to make it done easily. In this article, we’ll see how the function wp_login_form() works and how to implement it in WordPress sidebar.

The function
wp_login_form() takes many parameters:
  wp_login_form(array(
     'echo' => true,
     'redirect' => site_url($_SERVER['REQUEST_URI']),     
      'form_id' => 'loginform',
    'label_username' => __('Username'),
      'label_password' => __('Password'),
     'label_remember' => __('Remember Me'),
     'label_log_in' => __('Log In'),
      'id_username' => 'user_login',
    'id_password' => 'user_pass',
    'id_remember' => 'rememberme',
    'id_submit' => 'wp-submit',
    'remember' => true,
    'value_username' => ,
    'value_remember' => false
));
The most important are:
  • echo: display (true) or not (false) login form. If not, it returns HTML string that you can put anywhere. Default is true.
  • redirect: the URL of web page to redirect user to after login. The default value is site_url( $_SERVER['REQUEST_URI'] ), that means current URL.
  • form_id: ID of login form. Default is loginform. You might want to know this for styling the login form.
  • remember: (true/false) Whether to remember the values. Default is true.
To see all parameters and their meanings, you can go to the Codex.
Now, let’s see an example of wp_login_form’s usage. We’ll check if user is logged in or not. If user logged in, we’ll display a greeting and a logout link. If not, we’ll display a login form. So, open your sidebar.php file and paste the following code into it:

  global $user_login;
  if (is_user_logged_in()) {
      echo 'Hello, ', $user_login, '. <a href="', wp_logout_url(), '" title="Logout">Logout</a>';
  } else {
      wp_login_form();
  }

That’s really simple and clean, isn’t it?
Adding a login form in sidebar is a good way to improve user experience in your WordPress blog, especially when you want your users do everything in the front-end only.


Plugin for Facebook widget in wordpress

1. Copy this code and  save it in plugins folder activate the plugin and enjoy.

<?php
/*

 * Plugin Name:Facebook Like widget

author: Arunendra Pratap Rai

*/

class apr_facebook_widget extends WP_Widget {

    /** constructor */

    function apr_facebook_widget() {

        parent::WP_Widget(false, $name = __('(apr) Facebook Like Box', 'ocmx'), $widget_options = __('Display a Facebook Like Box.','ocmx'));

    }

    /** @see WP_Widget::widget */

    function widget($args, $instance) {

        extract( $args );

        if(isset($instance["title"]))

$title = esc_attr($instance["title"]);

if(isset($instance["facebookpage"]))

$facebookpage = esc_attr($instance["facebookpage"]);

if(isset($instance["height"]))

$height = esc_attr($instance["height"]);

if(isset($instance["faces"]))

$faces = esc_attr($instance["faces"]);

if(isset($instance["colorscheme"]))

$colorscheme = esc_attr($instance["colorscheme"]);

if(isset($instance["stream"]))

$stream = esc_attr($instance["stream"]);

if(isset($instance["border"]))

$border = esc_attr($instance["border"]);      

     

echo $before_widget; ?>

<?php echo $before_title; ?>

            <?php echo $instance['title']; ?>

            <?php echo $after_title; ?>

            

         

        <?php echo $after_widget;

    }

    /** @see WP_Widget::update */

    function update($new_instance, $old_instance) {

        return $new_instance;

    }

    /** @see WP_Widget::form */

    function form($instance) {

        if(isset($instance["title"]))

$title = esc_attr($instance["title"]);

if(isset($instance["facebookpage"]))

$facebookpage = esc_attr($instance["facebookpage"]);

if(isset($instance["height"]))

$height = esc_attr($instance["height"]);

if(isset($instance["faces"]))

$faces = esc_attr($instance["faces"]);

if(isset($instance["colorscheme"]))

$colorscheme = esc_attr($instance["colorscheme"]);

if(isset($instance["stream"]))

$stream = esc_attr($instance["stream"]);

if(isset($instance["border"]))

$border = esc_attr($instance["border"]);

        ?>

            

<?php } } // class FooWidget //This sample widget can then be registered in the widgets_init hook: // register FooWidget widget add_action('widgets_init', create_function('', 'return register_widget("apr_facebook_widget");')); ?>