Save data from .CSV file to database

1. Save data from .CSV file to database using php

public function savefile()
    {
        die('Remove die to action');
        error_reporting(E_ALL ^ E_NOTICE);   
        if(!defined('DS')) {
            define('DS',DIRECTORY_SEPARATOR);
        }
        mysql_connect('localhost', 'dbuser', 'db_password');
        mysql_select_db('db_name');

Executing php inside a WordPress widget

Executing php inside a WordPress widget without any plugin

Sometimes in your WordPress theme you need to execute custom php code in a widget, because you want to display different information according to the category you are in, or simply because you need to execute a php script into that widget.
There are a lot of plugins doing this task, adding a new type of widget generally called “php widget”, but rather than installing a plugin this simple job can be done simply adding in functions.php file of your theme these few lines:
/*-------------------------  START -------------------------------------*/
add_filter('widget_text','execute_php',100);
function execute_php($html){
     if(strpos($html,"<"."?php")!==false){
          ob_start();
          eval("?".">".$html);
          $html=ob_get_contents();
          ob_end_clean();
     }
     return $html;
}

/*---------------------------- END ----------------------------------*/ 

Which will turn the default Text widget into a php enabled widget.
Adding this feature directly to functions.php allows you to create a theme with this built in feature without the need of an external plugin.

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. }