Saturday 25 June 2016

How to Create Custom Plugin?

Hi, Learn here to create Simple form  Plugin.
Create 3 files & 1 directory as "images" name.
1. custom_fields_variable.php
2. readme.txt
3. uninstall.php

1> Here, "images" Directory for Upoad Images like, logo.

2> "readme.txt" for description about your Plugin.

3>  Copy following code in "custom_fields_variable.php"  file.
      All details are described in comments.

<?php
/**
* Plugin Name: Custom Fields Variable
* Plugin URI: #
* Description: This plugin is create custom fields & its variable. You can print this value to anywhere using variable.
* Version: 1.0
* Author: Ankit Shah
* Author URI: http://itnewcode.blogspot.com/
* License: GPL
*/
?>
<?php
/*
we’ll do is create a menu entry in the backend where we can place our settings user interface:
add_menu_page() function arguments:
1. Page title – used in the title tag of the page (shown in the browser bar) when it is displayed.
2. Menu title – used in the menu on the left.
3. Capability – the user level allowed to access the page.
4. Menu slug – the slug used for the page in the URL.
5. Function – the name of the function you will be using to output the content of the page.
6. Icon – A url to an image or a Dashicons string.
7. Position – The position of your item within the whole menu.
*/

// create custom plugin settings menu
add_action('admin_menu', 'custom_fields_variable_plugin_create_menu');

function custom_fields_variable_plugin_create_menu() {

//create new top-level menu
add_menu_page('Custom Fields Variable Plugin Settings', 'CFV Settings', 'administrator', __FILE__, 'custom_fields_variable_plugin_settings_page' , plugins_url('/images/icon.png', __FILE__) );

//call register settings function
add_action( 'admin_init', 'register_custom_fields_variable_plugin_settings' );
}


function register_custom_fields_variable_plugin_settings() {
//register our settings
register_setting( 'cfv-plugin-settings-group', 'header_logo' );  // For file upload
register_setting( 'cfv-plugin-settings-group', 'aks_name' );
register_setting( 'cfv-plugin-settings-group', 'aks_textarea' );
register_setting( 'cfv-plugin-settings-group', 'aks_radio' );
register_setting( 'cfv-plugin-settings-group', 'aks_checkbox1' );
register_setting( 'cfv-plugin-settings-group', 'aks_checkbox2' );
register_setting( 'cfv-plugin-settings-group', 'aks_color' );
register_setting( 'cfv-plugin-settings-group', 'aks_email' );
register_setting( 'cfv-plugin-settings-group', 'aks_number' );
register_setting( 'cfv-plugin-settings-group', 'aks_tel' );
register_setting( 'cfv-plugin-settings-group', 'aks_time' );
register_setting( 'cfv-plugin-settings-group', 'aks_url' );
register_setting( 'cfv-plugin-settings-group', 'aks_week' );
register_setting( 'cfv-plugin-settings-group', 'aks_month' );
register_setting( 'cfv-plugin-settings-group', 'aks_date' );
}

function custom_fields_variable_plugin_settings_page() {
?>
<div class="wrap">
<h2>Your Plugin Name</h2>

<form method="post" action="options.php">
    <?php settings_fields( 'cfv-plugin-settings-group' ); ?>
    <?php do_settings_sections( 'cfv-plugin-settings-group' ); ?>
<?php
//Upload file Code START
?>
<?php
if(function_exists( 'wp_enqueue_media' )){
    wp_enqueue_media();
}else{
    wp_enqueue_style('thickbox');
    wp_enqueue_script('media-upload');
    wp_enqueue_script('thickbox');
}
?>
<p><strong>Header Logo Image URL:</strong><br />
                <img class="header_logo" src="<?php echo get_option('header_logo'); ?>" height="100" width="100"/>
                <input class="header_logo_url" type="text" name="header_logo" size="60" value="<?php echo get_option('header_logo'); ?>">
                <a href="#" class="header_logo_upload">Upload</a>
</p>  

<script>
    jQuery(document).ready(function($) {
        $('.header_logo_upload').click(function(e) {
            e.preventDefault();

            var custom_uploader = wp.media({
                title: 'Custom Image',
                button: {
                    text: 'Upload Image'
                },
                multiple: false  // Set this to true to allow multiple files to be selected
            })
            .on('select', function() {
                var attachment = custom_uploader.state().get('selection').first().toJSON();
                $('.header_logo').attr('src', attachment.url);
                $('.header_logo_url').val(attachment.url);

            })
            .open();
        });
    });
</script>
<?php
//Upload file Code END
?>
    <table class="form-table">
<tr valign="top">
        <th scope="row">Name:</th>
        <td><input type="text" name="aks_name" value="<?php echo esc_attr( get_option('aks_name') ); ?>" /></td>
        </tr>

<tr valign="top">
        <th scope="row">Textarea:</th>
        <td><textarea name="aks_textarea" rows="3" cols="50"><?php echo esc_attr( get_option('aks_textarea') ); ?></textarea></td>
        </tr>

<tr valign="top">
        <th scope="row">Radio:</th>
        <td><input type="radio" name="aks_radio" value="Male" <?php if ( Male == esc_attr( get_option('aks_radio') ) ) echo 'checked="checked"'; ?> />Male
<input type="radio" name="aks_radio" value="Female" <?php if ( Female == esc_attr( get_option('aks_radio') ) ) echo 'checked="checked"'; ?> />Female
</td>
        </tr>

<tr valign="top">
        <th scope="row">checkbox:</th>
        <td><input type="checkbox" name="aks_checkbox1" value="checkbox1" <?php if ( checkbox1 == esc_attr( get_option('aks_checkbox1') ) ) echo 'checked="checked"'; ?> />Male
<input type="checkbox" name="aks_checkbox2" value="checkbox2" <?php if ( checkbox2 == esc_attr( get_option('aks_checkbox2') ) ) echo 'checked="checked"'; ?> />Female
</td>
        </tr>

<tr valign="top">
        <th scope="row">Color:</th>
        <td><input type="color" name="aks_color" value="<?php echo esc_attr( get_option('aks_color') ); ?>" /></td>
        </tr>

<tr valign="top">
        <th scope="row">E-mail:</th>
        <td><input type="email" name="aks_email" value="<?php echo esc_attr( get_option('aks_email') ); ?>" /></td>
        </tr>

<tr valign="top">
        <th scope="row">Telephone Number:</th>
        <td><input type="number" name="aks_number" value="<?php echo esc_attr( get_option('aks_number') ); ?>" /></td>
        </tr>

<tr valign="top">
        <th scope="row">Mobile Number:</th>
        <td><input type="tel" name="aks_tel" value="<?php echo esc_attr( get_option('aks_tel') ); ?>" /></td>
        </tr>

<tr valign="top">
        <th scope="row">Time:</th>
        <td><input type="time" name="aks_time" value="<?php echo esc_attr( get_option('aks_time') ); ?>" /></td>
        </tr>

<tr valign="top">
        <th scope="row">URL:</th>
        <td><input type="url" name="aks_url" value="<?php echo esc_attr( get_option('aks_url') ); ?>" /></td>
        </tr>

<tr valign="top">
        <th scope="row">Week:</th>
        <td><input type="week" name="aks_week" value="<?php echo esc_attr( get_option('aks_week') ); ?>" /></td>
        </tr>

<tr valign="top">
        <th scope="row">Month:</th>
        <td><input type="month" name="aks_month" value="<?php echo esc_attr( get_option('aks_month') ); ?>" /></td>
        </tr>

<tr valign="top">
        <th scope="row">Date:</th>
        <td><input type="date" name="aks_date" value="<?php echo esc_attr( get_option('aks_date') ); ?>" /></td>
        </tr>

    </table>
    <?php submit_button(); ?>
</form>
</div>
<?php } ?>
<?php
/*
To Print specific value of This fields paste following code:
$aks_name = get_option( 'aks_name' );
     print_r($aks_name);


//for full data loop Example:
global $wpdb;
$table_name = $wpdb->prefix . 'options';
$results = $wpdb->get_results ("SELECT * FROM $table_name;");
//print_r($results);
echo '<select>';
foreach ( $results as $result ) {
    echo '<option>'.$result->option_name.'</option>';
}
echo '</select>';

*/
?>
<?php
add_action( 'wp_head', 'api_ids' );
/*for check this code is working or not print variable & check inspect element to <head> tag.
This variable can any where in code beacuse of it is global variable  */

function api_ids() {

global $header_logo;
$header_logo = get_option( 'header_logo' );
// print_r($header_logo);

global $aks_name;
$aks_name = get_option( 'aks_name' );
// print_r($aks_name);

global $aks_textarea;
$aks_textarea = get_option( 'aks_textarea' );
// print_r($aks_textarea);

global $aks_radio;
$aks_radio = get_option( 'aks_radio' );
// print_r($aks_radio);

global $aks_checkbox1;
$aks_checkbox1 = get_option( 'aks_checkbox1' );
// print_r($aks_checkbox1);

global $aks_checkbox2;
$aks_checkbox2 = get_option( 'aks_checkbox2' );
// print_r($aks_checkbox2);

global $aks_color;
$aks_color = get_option( 'aks_color' );
// print_r($aks_color);

global $aks_email;
$aks_email = get_option( 'aks_email' );
// print_r($aks_email);

global $aks_number;
$aks_number = get_option( 'aks_number' );
// print_r($aks_number);

global $aks_tel;
$aks_tel = get_option( 'aks_tel' );
// print_r($aks_tel);

global $aks_time;
$aks_time = get_option( 'aks_time' );
// print_r($aks_time);

global $aks_url;
$aks_url = get_option( 'aks_url' );
// print_r($aks_url);

global $aks_week;
$aks_week = get_option( 'aks_week' );
// print_r($aks_week);

global $aks_month;
$aks_month = get_option( 'aks_month' );
// print_r($aks_month);

global $aks_date;
$aks_date = get_option( 'aks_date' );
// print_r($aks_date);

/*
Now You can print this variable any where like:
echo $header_logo;
echo $aks_name;
echo $aks_textarea;
echo $aks_radio;
echo $aks_checkbox1;
echo $aks_checkbox2;
echo $aks_color;
echo $aks_email;
echo $aks_number;
echo $aks_tel;
echo $aks_time;
echo $aks_url;
echo $aks_week;
echo $aks_month;
echo $aks_date;
*/
}



/*
If plugin active then & only then code execute.
first argument is for path,
Seconf argument is function.
*/
register_activation_hook( __FILE__, 'api_ids' );



/*
If plugin deactive remove code of plugin.
first argument is for path,
Seconf argument is function.
here no function defined.

Example:
register_deactivation_hook( __FILE__, 'deactive function' );
*/


/*
You can use for uninstall register_uninstall_hook() function or "uninstall.php" page.
we created "uninstall.php" page.
If plugin uninstall all data remove.
first argument is for path,
Seconf argument is function.

Example:
register_uninstall_hook( __FILE__, 'uninstall_plugin_function' );
function uninstall_plugin_function() {
  // Uninstallation code comes here
        // If uninstall is not called from WordPress, exit
if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit();
}

//all register_setting() function add here & delete it
$header_logo = 'header_logo';
$aks_name = 'aks_name';
$aks_textarea = 'aks_textarea';
$aks_radio = 'aks_radio';
$aks_checkbox1 = 'aks_checkbox1';
$aks_checkbox2 = 'aks_checkbox2';
$aks_color = 'aks_color';
$aks_email = 'aks_email';
$aks_number = 'aks_number';
$aks_tel = 'aks_tel';
$aks_time = 'aks_time';
$aks_url = 'aks_url';
$aks_week = 'aks_week';
$aks_month = 'aks_month';
$aks_date = 'aks_date';


delete_option($header_logo);
delete_option($aks_name);
delete_option($aks_textarea);
delete_option($aks_radio);
delete_option($aks_checkbox1);
delete_option($aks_checkbox2);
delete_option($aks_color);
delete_option($aks_email);
delete_option($aks_number);
delete_option($aks_tel);
delete_option($aks_time);
delete_option($aks_url);
delete_option($aks_week);
delete_option($aks_month);
delete_option($aks_date);
}
*/

?>


4> Copy following code in "uninstall.php" file.
     This code will execute when delete or uninstall that plugin.

<?php

// If uninstall is not called from WordPress, exit
if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) {
    exit();
}

/*
all register_setting() function add here & delete it
*/
$header_logo = 'header_logo';
$aks_name = 'aks_name';
$aks_textarea = 'aks_textarea';
$aks_radio = 'aks_radio';
$aks_checkbox1 = 'aks_checkbox1';
$aks_checkbox2 = 'aks_checkbox2';
$aks_color = 'aks_color';
$aks_email = 'aks_email';
$aks_number = 'aks_number';
$aks_tel = 'aks_tel';
$aks_time = 'aks_time';
$aks_url = 'aks_url';
$aks_week = 'aks_week';
$aks_month = 'aks_month';
$aks_date = 'aks_date';




delete_option($header_logo);
delete_option($aks_name);
delete_option($aks_textarea);
delete_option($aks_radio);
delete_option($aks_checkbox1);
delete_option($aks_checkbox2);
delete_option($aks_color);
delete_option($aks_email);
delete_option($aks_number);
delete_option($aks_tel);
delete_option($aks_time);
delete_option($aks_url);
delete_option($aks_week);
delete_option($aks_month);
delete_option($aks_date);



/*
// Drop a custom db table if you created a table
global $wpdb;
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}tablename" );
*/
?>




Click here to Download This Plugin.

For more Interesting, Useful Article & codes visit IT New Code.

Friday 24 June 2016

Learn Various Anchor tag Usage.

The <a> Anchor tag use for the hyperlink, Always <a> Anchor tag is use for link one page to another page or Same page jump to selected div or section.

The most important attribute of <a> tag is the "href", which is used for destination link.
Another attribute is "target", Use for where to open the linked document.
There are 4 values available for it _blank, _parent, _self & _top.

By default, <a> anchor tag will appear as follows:

Unvisited link looks as underlined and blue color,
Visited link looks as underlined and purple color,
& Active link looks as underlined and red color.

Style for <a> Anchor tag:
<style>
a {color:blue;}
a:link    {color:green;}
a:visited {color:pink;}
a:hover   {color:red;}
a:active  {color:yellow;}
</style>


Example:-
<a href="http://itnewcode.blogspot.in/" target="_blank">IT New Code</a>
here,
href for Url or Path locaction

target for where to open the linked document it may be 4 types(_blank, _parent, _self, _top)



Skype link:-
<a href="skype:skaype_name?call">Skype name</a>
**************************************************************

Call link:-
<a href="tel:3177594940">317.759.4940</a>
**************************************************************

Mail link:-
<a href="mailto:test@gmail.com">test@gmail.com</a>
**************************************************************

Mail with subject link:-
<a href="mailto:test@gmail.com?Subject=Your Subject">test@gmail.com</a>
**************************************************************

Gmail email link:-
<a href="mailto:http://mail.google.com/mail/?view=cm&fs=1&tf=1&to=test@gmail.com&su=Your Subject">test@gmail.com</a>
**************************************************************

Vimeo embed code:-
<div class="video-holder">&nbsp;<iframe src="http://player.vimeo.com/video/#####"  
width="561" height="316" frameborder="0" webkitAllowFullScreen mozallowfullscreen
allowFullScreen></iframe></p>
**************************************************************

You Tube embed code:-
<iframe title="YouTube video player" class="youtube-player" type="text/html"
width="640" height="390" src="http://www.youtube.com/embed/##########"
frameborder="0" allowFullScreen></iframe>
**************************************************************

Open Multiple windows link on single click:-
<a href="https://www.facebook.com/" target="_blank" onclick="window.open('http://www.google.com/'); window.open('http://www.yahoo.com/');">Single Click Open Multiple windows link</a>
**************************************************************

Map Anchor tag:-
<a class="to-map" href="https://maps.google.com/?q=loc:-43.6298474,172.7269425">13 Hunters Rd, Diamond Harbour 8971, New Zealand</a>

Here,
-43.6298474 is latitude and
172.7269425 is logitude.
**************************************************************

Map Embed & Anchor tag:-
<iframe src = "https://maps.google.com/maps?q=10.305385,77.923029&hl=es;z=14&amp;output=embed"></iframe>
<a href="https://maps.google.com/maps?q=10.305385,77.923029&hl=es;z=14&amp;output=embed" style="color:#0000FF;text-align:left" target="_blank">See map bigger</a>

Here,
-10.305385 is latitude and
77.923029 is logitude.
"es" is spanish language and "z" is the zoom that will have the map.
**************************************************************

Google Calendar Add to your account Or Subscribe code:-
<a href="http://www.google.com/calendar/render?cid=[CALENDAR-XML-LINK]" target="_blank"><img border="0" src="//www.google.com/calendar/images/ext/gc_button6.gif"></a>

Example:
<a href="http://www.google.com/calendar/render?cid=http%3A%2F%2Fwww.google.com%2Fcalendar%2Ffeeds%2Fsstx.org_siq5ectrvg921eipq0qdu5fho4%2540group.calendar.google.com%2Fpublic%2Fbasic" target="_blank"><img border="0" src="//www.google.com/calendar/images/ext/gc_button6.gif"></a>
**************************************************************

Pass Variable data in Php Anchor Tag:-
<?php $id=10; ?>
<a class='link' href=\"Adminupdateotherprofile.php?id=$id\">VIEW & EDIT</a>
& receive it as following
<?php echo $_GET['id']; ?>
**************************************************************

Countdown Timer:-
https://www.timeanddate.com/clocks/freecountdown.html
https://countingdownto.com/countdown-widgets/edit/event-name-countdown-clock-0b98cd98-de66-4280-b9d2-1abf6a111087
**************************************************************

API Create (Social Network Integrations):-
Facebook, Google+, Instagram, PayPal, Twitter, LinkedIn, Amazon, Yahoo, Windows Live, Tumblr, BufferApp, Foursquare, VK.com
http://wpweb.co.in/documents/social-network-integration/
**************************************************************

For more Interesting, Useful Article & codes visit IT New Code.

How to Fetch Data from Database of all users in table structre, Open Each user profile & Update it? How to Get Value By passing Variable as id?

Create three files & 1 directory create called "upload".
1. alluserfetchdata.php
2. Adminupdateotherprofile.php
3. Adminupdateotherprofileprocess.php

1> Copy Following code in "alluserfetchdata.php" file.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Fetch data</title>
</head>

<body>
<table width="200" border="1">
 <tr>
<th>No</th>
<th>name</th>
<th>gender</th>
<th>Discription</th>
<th>View</th>
 </tr>

<?php

 $con=mysql_connect('localhost','root','');
if(!$con)
{
echo "Connection error".mysql_error();
}
$db=mysql_select_db('test1');
$sql="select * from registration";
echo $sql;
$i=1;
$result=mysql_query($sql,$con);
while($row=mysql_fetch_array($result))
{
$id=$row['id'];

echo "<tr>";

echo "<td>".$i."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['gender']."</td>";
echo "<td>".$row['discreption']."</td>";
echo "<td><a class='link' href=\"Adminupdateotherprofile.php?id=$id\">VIEW & EDIT</a></td>";
echo "</tr>";
$i++;
}
?>
</table>

</body>
</html>


2> Copy Following code in "Adminupdateotherprofile.php" file.
      Here,We Get data by passing id as variable & get all that Id Data.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Selected person data</title>
<style>
input[type=text]{color:#0F3; width:300px; outline:red;}
</style>
</head>

<body>
<?php
//session_start();
//$id=$_SESSION['id'];
//echo $_SESSION['id'];
$con=mysql_connect('localhost','root','');
if(!$con)
{
echo "Connection error".mysql_error();
}
$db=mysql_select_db('test1');
$sql="select * from registration where id=".$_GET['id'];
//echo $sql;
$result=mysql_query($sql,$con);
while($row=mysql_fetch_array($result))
{
?>
<form method="post" action="Adminupdateotherprofileprocess.php" enctype="multipart/form-data">
<table width="200" border="1">
<input type="hidden" name="id" value="<?php echo $row['id']; ?>" />
 <tr>
<td>Name:</td>
<td><input type="text" name="name" value="<?php echo $row['name']; ?>"/></td>
 </tr>
 <tr>
<td>Gender:</td>
<td><input type="radio" name="gender" value="<?php echo $row['gender']; ?>" checked="checked"/><?php echo $row['gender']; ?>
<?php
if($row['gender']=='Male')
{?>
<input type="radio" name="gender" value="Female"/>Female
<?php
}
else
{?>
<input type="radio" name="gender" value="Male"/>Male
<?php
}
?></td>
 </tr>
 <tr>
<td>discription</td>
<td><textarea name="discreption" ><?php echo $row['discreption']; ?></textarea></td>
 </tr>
 <tr>
<td>Photo:</td>
<td><input type="file" name="photo" value="<?php echo $row['photo']; ?>" required="required"/></td>
 </tr>
 <tr>
<td>Image:</td>
<td><img src="<?php echo $row['photo']; ?>" width="300px" height="300px"/></td>
 </tr>
</table>
<input type="submit" name="update" value="UPDATE" />
</form>
<?php
}
?>

</body>
</html>

 

3> Copy Following code in "Adminupdateotherprofileprocess.php" file.
     UPDATE profile here.
<?php
session_start();
$id=$_POST['id'];
$name=$_POST['name'];
$gender=$_POST['gender'];
//$photo=$_POST['photo'];
$discreption=$_POST['discreption'];


$dir="upload/";
$path=$dir.basename($_FILES['photo']['name']);
move_uploaded_file($_FILES['photo']['tmp_name'],$path);

//$id=$_SESSION['id'];

$con=mysql_connect('localhost','root','');
if(!$con)
{
echo "Connection error".mysql_error();
}
$db=mysql_select_db('test1');
$sql="UPDATE `registration` SET `name`='$name',`gender`='$gender',`photo`='$path',`discreption`='$discreption' WHERE id='$id'";
echo $sql;
$result=mysql_query($sql,$con);
if($result>0)
{
echo "Successfull";
}
else
{
echo "fail";
}


To download code Click Here.

For more Interesting, Useful Article & codes visit IT New Code.

How to Fetch Data from Database as Single person Profile & update Profile data?

Create two files &  1 directory create called "upload".
1. profile.php
2. profileupdateprocess.php


1> Copy Following code in "profile.php" file.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Profile (Fetch data)</title>
</head>

<body>
<?php
session_start();
$id=$_SESSION['id'];
//echo $_SESSION['id'];
$con=mysql_connect('localhost','root','');
if(!$con)
{
echo "Connection error".mysql_error();
}
$db=mysql_select_db('test1');
$sql="select * from registration where id='$id'";
//echo $sql;
$result=mysql_query($sql,$con);
while($row=mysql_fetch_array($result))
{
    ?>
    <form method="post" action="profileupdateprocess.php" enctype="multipart/form-data">
<table width="200" border="1">
  <tr>
    <td>Name:</td>
    <td><input type="text" name="name" value="<?php echo $row['name']; ?>"/></td>
  </tr>
  <tr>
    <td>Gender:</td>
    <td><input type="radio" name="gender" value="<?php echo $row['gender']; ?>" checked="checked"/><?php echo $row['gender']; ?>
<?php
    if($row['gender']=='Male')
    {?>
<input type="radio" name="gender" value="Female"/>Female
    <?php
}
    else
    {?>
<input type="radio" name="gender" value="Male"/>Male
    <?php
}
?></td>
  </tr>
  <tr>
    <td>discription</td>
    <td><textarea name="discreption" ><?php echo $row['discreption']; ?></textarea></td>
  </tr>
  <tr>
    <td>Photo:</td>
    <td><input type="file" name="photo" value="<?php echo $row['photo']; ?>" required="required"/></td>
  </tr>
  <tr>
    <td>Image:</td>
    <td><img src="<?php echo $row['photo']; ?>" width="300px" height="300px"/></td>
  </tr>
</table>
<input type="submit" name="update" value="UPDATE" />
</form>
<?php
}
?>
</body>
</html>


2> Copy Following code in "profileupdateprocess.php" file.
<?php
session_start();
$name=$_POST['name'];
$gender=$_POST['gender'];
//$photo=$_POST['photo'];
$discreption=$_POST['discreption'];


$dir="upload/";
$path=$dir.basename($_FILES['photo']['name']);
move_uploaded_file($_FILES['photo']['tmp_name'],$path);

$id=$_SESSION['id'];

$con=mysql_connect('localhost','root','');
if(!$con)
{
echo "Connection error".mysql_error();
}
$db=mysql_select_db('test1');
$sql="UPDATE `registration` SET `name`='$name',`gender`='$gender',`photo`='$path',`discreption`='$discreption' WHERE id='$id'";
echo $sql;
$result=mysql_query($sql,$con);
if($result>0)
{
echo "Successfull";
}
else
{
echo "fail";
}



To download code Click Here.

For more Interesting, Useful Article & codes visit IT New Code.

How to create Login Page with Login process?

Create two files.
1. Login.html
2. loginprocess.php

1> Put following code in "Login.html" file.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form method="post" action="loginprocess.php">
<table width="200" border="1">
 <tr>
<td>Username:</td>
<td><input type="text" name="uname" required="required"/></td>
 </tr>
 <tr>
<td>Password:</td>
<td><input type="password" name="pwd" required="required" /></td>
 </tr>
</table>
<input type="submit" value="SUBMIT"  />
</form>
</body>
</html>



2> Put following code in "loginprocess.php" file.
<?php
$uname=$_POST['uname'];
$pwd=$_POST['pwd'];

$con=mysql_connect('localhost','root','');
if(!$con)
{
echo "Connection error".mysql_error();
}
$db=mysql_select_db('test1');
$sql="select * from registration where name='$uname'";
$result=mysql_query($sql,$con);
while($row=mysql_fetch_array($result))
{
$dbpwd=$row['password'];
$dbid=$row['id'];
if($pwd==$dbpwd)
{
session_start();
$_SESSION['id']=$dbid;
?>
                             <!-- iF sussessfully  then Alert-->
<script type="text/javascript">
alert('Successfully  Authenticated.');
document.location='profile.php';
</script>
<?php
        }
//header('Location:profile.php');
//echo"Login Sussessfully";

else
{
?>
        <!------ iF Fail  then Alert -->
<script type="text/javascript">
alert('Fail to Authenticate.');
document.location='Login.html';
</script>

<?php
//echo"fail";
}
}
?>


To download code Click Here.

For more Interesting, Useful Article & codes visit IT New Code.

How to Create Registration Form with file Upload & Store in Database?

First Create 3 Things.
1. registration.html       ( Create file)
2. registrationprocess.php      ( Create file )
3. upload         ( Create Directory )

1> Copy Following code in "registration.html" file.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registration</title>
</head>

<body>
<form method="post" action="registrationprocess.php" enctype="multipart/form-data">
<table width="200" border="1">
  <tr>
    <td>Name:</td>
    <td><input type="text" name="name" required="required" /></td>
  </tr>
  <tr>
    <td>Gender:</td>
    <td><input type="radio" name="gender" required="required" value="Male"/>Male
    <input type="radio" name="gender" required="required" value="Female"/>Female</td>
  </tr>
  <tr>
    <td>Photo:</td>
    <td><input type="file" name="photo" required="required"/></td>
  </tr>
  <tr>
    <td>discription</td>
    <td><textarea name="discreption" required="required"></textarea></td>
  </tr>
  <tr>
    <td>Password:</td>
    <td><input type="password" name="pwd" minlength="6" required="required" /></td>
  </tr>
   <tr>
    <td>Conform Password:</td>
    <td><input type="password" name="repwd" minlength="6" required="required" /></td>
  </tr>
</table>
<input type="submit" value="SUBMIT" />
</form>
</body>
</html>

Here, in <form> tag enctype="multipart/form-data" code is required for file upload.


2> Put following code in "registrationprocess.php" file.
<?php
$name=$_POST['name'];
$gender=$_POST['gender'];
//$photo=$_POST['photo'];
$discreption=$_POST['discreption'];
$pwd=$_POST['pwd'];
$repwd=$_POST['repwd'];

$dir="upload/";
$path=$dir.basename($_FILES['photo']['name']);
move_uploaded_file($_FILES['photo']['tmp_name'],$path);

if($pwd==$repwd)
{
$con=mysql_connect('localhost','root','');
if(!$con)
{
echo "Connection error".mysql_error();
}
$db=mysql_select_db('test1');

$query="insert into registration(name,gender,photo,discreption,password)values('$name','$gender','$path','$discreption','$pwd')";
echo $query;

$i=mysql_query($query,$con);
if($i>0)
{
echo "Successfull";
}
else
{
echo "Fail";
}
}
else
{
echo "Password not match";
}
?>

Here,
$dir="upload/";
$path=$dir.basename($_FILES['photo']['name']);
move_uploaded_file($_FILES['photo']['tmp_name'],$path);
code for file upload.
&
insert into registration(name,gender,photo,discreption,password)values('$name','$gender','$path','$discreption','$pwd')
code for insert in database.


3> Create Directory "upload"


To download full code Click Here.

For more Interesting, Useful Article & codes visit IT New Code.

How to Create Custom Post Type ( CPT ) in WordPress?

There is Some good plugin available for Custom Post Type.
"Custom Post Type UI" Plugin can download from "https://wordpress.org/plugins/custom-post-type-ui/" URL.



For Manually Create "Custom Post Type" (CPT) follow the following Steps.
1> Create CUSTOM POST TYPE  (Add Fol1owing code to "functions.php" file or Plugin file)
<?php
 // Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );

// Our custom post type function. Here, "movies" is our new Custom Post Type.
function create_posttype() {
register_post_type( 'movies',
// CPT Options
array(
'labels' => array(
'name' => __( 'Movies' ),
'singular_name' => __( 'Movie' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'movies'),
)
);
}



/* Creating a function to create our Custom Post Type
 * Text Domain: twentysixteen in "style.css" file you get it.
 */

function custom_post_type() {

// Set UI labels for Custom Post Type
$labels = array(
'name'                => _x( 'Movies', 'Post Type General Name', 'twentythirteen' ),
'singular_name'       => _x( 'Movie', 'Post Type Singular Name', 'twentythirteen' ),
'menu_name'           => __( 'Movies', 'twentythirteen' ),
'parent_item_colon'   => __( 'Parent Movie', 'twentythirteen' ),
'all_items'           => __( 'All Movies', 'twentythirteen' ),
'view_item'           => __( 'View Movie', 'twentythirteen' ),
'add_new_item'        => __( 'Add New Movie', 'twentythirteen' ),
'add_new'             => __( 'Add New', 'twentythirteen' ),
'edit_item'           => __( 'Edit Movie', 'twentythirteen' ),
'update_item'         => __( 'Update Movie', 'twentythirteen' ),
'search_items'        => __( 'Search Movie', 'twentythirteen' ),
'not_found'           => __( 'Not Found', 'twentythirteen' ),
'not_found_in_trash'  => __( 'Not found in Trash', 'twentythirteen' ),
);


// Set other options for Custom Post Type
$args = array(
'label'               => __( 'movies', 'twentythirteen' ),
'description'         => __( 'Movie news and reviews', 'twentythirteen' ),
'labels'              => $labels,
// Features this CPT supports in Post Editor
'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
// You can associate this CPT with a taxonomy or custom taxonomy.
'taxonomies'          => array( 'genres' ),
/* A hierarchical CPT is like Pages and can have
* Parent and child items. A non-hierarchical CPT
* is like Posts.
*/
'hierarchical'        => false,
'public'              => true,
'show_ui'             => true,
'show_in_menu'        => true,
'show_in_nav_menus'   => true,
'show_in_admin_bar'   => true,
'menu_position'       => 5,
'can_export'          => true,
'has_archive'         => true,
'exclude_from_search' => false,
'publicly_queryable'  => true,
'capability_type'     => 'page',
);

// Registering your Custom Post Type
register_post_type( 'movies', $args );
}

/* Hook into the 'init' action so that the function
* Containing our post type registration is not
* unnecessarily executed.
*/

add_action( 'init', 'custom_post_type', 0 );
?>




2> For watch in front Custom Post Type

 If you are using SEO friendly permalinks then
 http://example.com/movies
 Else
 http://example.com/?post_type=movies

If you want to change the output look of archive page then,
Copy & Paste "archive.php" theme file.
Then rename it "archive-{posttype}.php". Like "archive-movies.php".
sample code add in "archive-movies.php" file
<?php
get_header();
if(have_posts()) : while(have_posts()) : the_post();
the_title();
echo '<div class="entry-content">';
the_content();
echo '</div>';
endwhile; endif;
get_footer();
?>


 If you want to change the output look of post page then,
 Copy & Paste "single.php" theme file.
 Then rename it "single-{posttype}.php". Like "single-movies.php".




3> Displaying Custom Post Types on The Front Page (add following code in "functions.php" or plugin file)

add_action( 'pre_get_posts', 'add_my_post_types_to_query' );

function add_my_post_types_to_query( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'post', 'movies' ) );
return $query;
}


4> For Querying Custom Post Types
Example Code:-
<?php
$args = array( 'post_type' => 'movies', 'posts_per_page' => 10 );
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="entry-content">
<?php the_content(); ?>
</div>
<?php wp_reset_postdata(); ?>
<?php else:  ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>


5> For Displaying Custom Post Types in Widgets
First thing you need to do is install and activate the "Ultimate Posts Widget" plugin. Upon activation, simply go to Appearance » Widgets and drag and drop the Ultimate Posts widget to a sidebar.


For more Interesting, Useful Article & codes visit IT New Code.

Sunday 19 June 2016

How to Create a Child Theme of WordPress?

There are 2 Good Plugin available for Create Child Theme.
1. One-Click Child Theme
2. Child Theme Configurator


You Can Manually create Child Theme as Follow:

There are 4 files in child Theme.
1. functions.php
2. rtl.css
3. screenshot.png ( This is Child Theme Image )
4. style.css


1> Create "functions.php" & Put Following code in it:

<?php
//
// Recommended way to include parent theme styles.
//  (Please see http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme)
//
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array('parent-style')
    );
}
//
// Your code goes below
//

2> Create "rtl.css" & Put Following code in it:

/*
Theme Name:     Child Theme Name
Template:    

Right to Left text support.
*/

@import url("../Parent Theme Directory name/rtl.css");


3> Image for Child Theme Rename your Image to "screenshot.png".
      Image minimum Size must be 880*660 px.


4> Create "style.css" & Put Following code in it:

/*
Theme Name:     Child Theme Name
Description:    Child Theme Description put here.
Author:         Author name
Template:       Parent Theme Directory Name

(optional values you can add: Theme URI, Author URI, Version, License, License URI, Tags, Text Domain)
*/


Put all file in Single folder. Your Child Theme is ready.

Put in WordPress Theme directory & Activate it from WordPress Admin Panel.


For more Interesting, Useful Article & codes visit IT New Code.

How to change Product page structure in WordPress, WooCommerce?

1> Create folder "woocommerce" in your theme.
2> your product page templte at following address:
   "/public_html/wp-content/plugins/woocommerce/templates"
3> download "content-single-product.php" file & put in theme "woocommerce" folder
4> "content-single-product.php" code Under standing below:
<?php
/**
* woocommerce_single_product_summary hook
*
* @hooked woocommerce_template_single_title - 5
* @hooked woocommerce_template_single_rating - 10
* @hooked woocommerce_template_single_price - 10
* @hooked woocommerce_template_single_excerpt - 20
* @hooked woocommerce_template_single_add_to_cart - 30
* @hooked woocommerce_template_single_meta - 40
* @hooked woocommerce_template_single_sharing - 50
*/

do_action( 'woocommerce_single_product_summary' );
?>
Above code can be print product title,Price,short discription etc.
To change it go follwing path
"/public_html/wp-content/plugins/woocommerce/includes/wc-template-hooks.php" file.

You can see follwing code:
/**
* Product Summary Box.
*
* @see woocommerce_template_single_title()
* @see woocommerce_template_single_rating()
* @see woocommerce_template_single_price()
* @see woocommerce_template_single_excerpt()
* @see woocommerce_template_single_meta()
* @see woocommerce_template_single_sharing()
*/
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );

From here it comes output.

5> for remove any function copy following code in your "functions.php" file in your theme.
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );

Code for Product Title:-
<?php if( mfn_opts_get('shop-product-title') != 'sub' ): ?>
<center><h1 itemprop="name" class="product_title entry-title product_title"><?php the_title(); ?></h1></center>
<?php endif; ?>

Code for Short discription:-
<div itemprop="description" class="wooshortdiscription">
<?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt ) ?>
</div>

Take code from "/public_html/wp-content/plugins/woocommerce/templates/single-product" files & put in Your "content-single-product.php" as you need.

6> Never change original file because when its update your modified code will be lost.


    
For more Interesting, Useful Article & codes visit IT New Code.

How to Remove Tabs in product page in WordPress, WooCommerce?

Open Theme "function.php" then enter following code.


add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );

function woo_remove_product_tabs( $tabs ) {

    unset( $tabs['description'] );       // Remove the description tab
    unset( $tabs['reviews'] ); // Remove the reviews tab
    unset( $tabs['additional_information'] );   // Remove the additional information tab

    return $tabs;

}


For more Interesting, Useful Article & codes visit IT New Code.

How to remove some type sorting in WordPress, WooCommerce?

Open "function.php" file in your theme.
then enter following code.


// Modify the default WooCommerce orderby dropdown
//
// Options: menu_order, popularity, rating, date, price, price-desc

function my_woocommerce_catalog_orderby( $orderby ) {
    unset($orderby["price"]);
    unset($orderby["price-desc"]);
    return $orderby;
}
add_filter( "woocommerce_catalog_orderby", "my_woocommerce_catalog_orderby", 20 );



For more Interesting, Useful Article & codes visit IT New Code.

How to set Product image as use original Image in WordPress, WooCommerce?

1> Open WooCommerce Plugin in Plugins > woocommerce

2> Following templete for Product Image code
      templates/single-product/product-image.php

3> Following is "Product-image.php" code.
<?php

/**
 * Single Product Image
 *
 * @author WooThemes
 * @package WooCommerce/Templates
 * @version     2.0.14
 */

if ( ! defined( 'ABSPATH' ) ) {
  exit; // Exit if accessed directly
}

global $post, $woocommerce, $product;

?>
<div class="images">

<?php
    if ( has_post_thumbnail() ) {

      $image_title   = esc_attr( get_the_title( get_post_thumbnail_id() ) );
      $image_caption   = get_post( get_post_thumbnail_id() )->post_excerpt;
      $image_link    = wp_get_attachment_url( get_post_thumbnail_id() );
      $image         = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ), array(
        'title'  => $image_title,
        'alt'  => $image_title
        ) );

      $attachment_count = count( $product->get_gallery_attachment_ids() );

      if ( $attachment_count > 0 ) {
        $gallery = '[product-gallery]';
      } else {
        $gallery = '';
      }

      echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<a href="%s" itemprop="image" class="woocommerce-main-image zoom" title="%s" data-rel="prettyPhoto' . $gallery . '">%s</a>', $image_link, $image_caption, $image ), $post->ID );

    } else {

      echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="%s" />', wc_placeholder_img_src(), __( 'Placeholder', 'woocommerce' ) ), $post->ID );

    }
  ?>

<?php do_action( 'woocommerce_product_thumbnails' ); ?>

</div>


4> Replace Following code by "$image = the_post_thumbnail( 'large','style=max-width:100%;height:auto;');".

Code:-
    $image = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ), array(
        'title'  => $image_title,
        'alt'  => $image_title
        ) );

5> SAVE and Check on front.


For more Interesting, Useful Article & codes visit IT New Code.

How to Empty Price display on cart button WordPress, WooCommerce?

Add Following code to "function.php" file


function custom_woocommerce_is_purchasable( $purchasable, $product ){
    if( $product->get_price() == 0 ||  $product->get_price() == '')
        $purchasable = true;
    return $purchasable;
}
add_filter( 'woocommerce_is_purchasable', 'custom_woocommerce_is_purchasable', 10, 2 );



For more Interesting, Useful Article & codes visit IT New Code.

Saturday 18 June 2016

How to Disable payment Getway in WordPress, WooCommerce Plugin?

Add following code in "function.php" file.


Code:-
<?php
add_filter('woocommerce_cart_needs_payment', '__return_false');
?>



For more Interesting, Useful Article & codes visit IT New Code.

How to create Product "Add to Cart" type Button manually in WordPress, WooCommerce?

First create product in WooCommerce.

Then Where You want to put button Put following code:


Button anchor tag:-
----------------------------------------
<a href="/test_new_guided/?add-to-cart=2526">Add to Bag</a>


Add direct 5 product in cart:-
----------------------------------------
<a href="/test_new_guided/?add-to-cart=2526&quantity=5">Add to Bag</a>


Here, 2526 is product id.



For more Interesting, Useful Article & codes visit IT New Code.

How to Add new tab with contact form, Product form, Product Inquiry Form in Wordpress, WooCommerce?

1>  Install Contact form 7 plugin first.
    then create new form in it with following code:

 <p>Your Name (required)<br />
        [text* your-name] </p>

    <p>Your Email (required)<br />
        [email* your-email] </p>

    <p class="product_subject">Subject<br />
        [text your-subject class:product_name] </p>

    <p>Your Message<br />
        [textarea your-message] </p>

    <p>[submit "Send"]</p>


2>  Then open themes "function.php" file & put follwing code in it:

add_filter( 'woocommerce_product_tabs', 'product_enquiry_tab' );
function product_enquiry_tab( $tabs ) {

    $tabs['test_tab'] = array(
        'title'     => __( 'Enquire about Product', 'woocommerce' ),
        'priority'  => 50,
        'callback'  => 'product_enquiry_tab_form'
    );

    return $tabs;

}
function product_enquiry_tab_form() {
    global $product;
    //If you want to have product ID also
    //$product_id = $product->id;
    $subject    =   "Enquire about ".$product->post->post_title;

    echo "<h3>".$subject."</h3>";
    echo do_shortcode('[contact-form-7 id="19" title="Contact form 1_copy"]'); //add your contact form shortcode here ..

    ?>

    <script>
    (function($){
        $(".product_name").val("<?php echo $subject; ?>");
    })(jQuery);
    </script>
    <?php
}
    ?>


Its Done.



For more Interesting, Useful Article & codes visit IT New Code.

 

Copyright @ 2016 IT New Code | Developing Code | Designing Code.

Designed by: Ankit Shah