Sunday, 18 February 2018

How to create plugin in wordpress

How to create plugin in wordpress this very easy if you have some knowledge og php language. Now in this tutorial, you’ll learn how to create a complete WordPress plugin. The main reason to create a plugin is that it allows you to separate your code from the core code of WordPress. If anything will be wrong in your plugin, the rest of the site will run continue with same functionalty.

Step1. First of all create a folder and then create a single file with one line of content.
Folder Location  /wp-content/plugins/awtplugin
Create a file named awtplugin.php. Open the file in a text editor, and paste the following information.
   Plugin Name: Advanced Web Tutorial
   Plugin URI:
   description: Create AWT and spread joy
   Version: 1.1
   Author: Mr. Atul Sharma
   Author URI:
   License: GPL2
Only the plugin’s name is required. But if you intend to distribute your plugin, 
you should add as much data as possible. 
WordPress offers three great hooks to help you take care of this:
  • register_activation_hook() This hook allows you to create a function that runs when your plugin is activated. It takes the path to your main plugin file as the first argument, and the function that you want to run as the second argument. You can use this to check the version of your plugin, do some upgrades between versions, check for the correct PHP version and so on.
  • register_deactivation_hook() The name says it all. This function works like its counterpart above, but it runs whenever your plugin is deactivated. I suggest using the next function when deleting data; use this one just for general housekeeping.
  • register_uninstall_hook() This function runs when the website administrator deletes your plugin in WordPress’ back end. This is a great way to remove data that has been lying around, such as
Step 2 :

 * Adds a view to the post being viewed
 * Finds the current views of a post and adds one to it by updating
 * the postmeta. The meta key used is "awtpop_views".
 * @global object $post The post object
 * @return integer $new_views The number of views the post has
function awtpop_add_view() {
   if(is_single()) {
      global $post;
      $current_views = get_post_meta($post->ID, "awtpop_views", true);
      if(!isset($current_views) OR empty($current_views) OR !is_numeric($current_views) ) {
         $current_views = 0;
      $new_views = $current_views + 1;
      update_post_meta($post->ID, "awtpop_views", $new_views);
      return $new_views;

add_action("wp_head", "awtpop_add_view");

 * Retrieve the number of views for a post
 * Finds the current views for a post, returning 0 if there are none
 * @global object $post The post object
 * @return integer $current_views The number of views the post has
function awtpop_get_view_count() {
   global $post;
   $current_views = get_post_meta($post->ID, "awtpop_views", true);
   if(!isset($current_views) OR empty($current_views) OR !is_numeric($current_views) ) {
      $current_views = 0;

   return $current_views;

 * Displays a list of posts ordered by popularity
 * Shows a simple list of post titles ordered by their view count
 * @param integer $post_count The number of posts to show
 function awtpop_popularity_list($post_count = 10) {
  $args = array(
    "posts_per_page" => 10,
    "post_type" => "post",
    "post_status" => "publish",
    "meta_key" => "awtpop_views",
    "orderby" => "meta_value_num",
    "order" => "DESC"

  $awtpop_list = new WP_Query($args);

  if($awtpop_list->have_posts()) { echo "<ul>"; }

  while ( $awtpop_list->have_posts() ) : $awtpop_list->the_post();
    echo '<li><a href="'.get_permalink($post->ID).'">'.the_title('', '', false).'</a></li>';

  if($awtpop_list->have_posts()) { echo "</ul>";}


Saturday, 10 February 2018

how to get all share link of dropbox folder


Request and response formats

In general, the Dropbox API uses HTTP POST requests with JSON arguments and JSON responses. Request authentication is via OAuth 2.0 using the Authorization request header or authorization URL parameter.

/*// Step 1. For Call HTTP Autherization .

After that you will get this responce

// Step 2. This local Path is set in my API http://localhost/mydropbox/xyz.php
// Step 3.  You can use according to your need */

// List contents of home directory

    if(isset($_GET["access_token"])&& !empty($_GET["access_token"])){

    $auth_token = $_GET["access_token"];
    $root_path = '/math/';
    // create curl resource
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_URL, "");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $auth_token, 'Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array('path'=> $root_path,'recursive'=> true,'include_media_info'=> false,'include_deleted'=> false,'include_has_explicit_shared_members'=> false,'include_mounted_folders'=> true)));
    $result = curl_exec($ch);
    $array = json_decode(trim($result), TRUE);
    //echo "<pre>";print_r($array);exit;

Sunday, 12 November 2017

Validating field with tooltip validation

When using FormValidation with some server-side frameworks such as CakePHPSymfonyRailsSpring, etc, there is a relationship between the model name and the attributename of input.
For example, assuming that a user is modeled by classUser withfirstNamelastName usernameemails[] properties.

git set up command

=========== Use GIT command ==========

>> sudo mkdir foldername
>> cd foldername/
>> git init
>> git remote add origin 

>> git fetch   
[ User : git-user-name , Pwd : git-pwd ]
>> git pull origin HEAD:Branch      [ User , Pwd ]
>> git add file_name.php
>> git commit -m "comment for add file"
>> git push origin HEAD:Branch     [ User , Pwd ]

>> git remote set-url origin    (For Setting Github User)

=============Add sql file in Xamp in ubuntu ===========

/opt/lampp/bin/php start
/opt/lampp/bin/mysql start

/opt/lampp/bin/mysql -h localhost -u root -p

use DatabseName; 
source /home/atul/Downloads/xyz.sql
==============Edit for file permission in wordpress ===============
find /path/to/your/wordpress/install/ a
find /path/to/your/wordpress/install/ -type f -exec chmod 644 {} \;
================== Add IP on host =================

sudo gedit /etc/hostname /etc/hosts
cd /etc
sudo gedit host


Wednesday, 16 November 2016

basic commad of svn

find . -type d -name .svn -print0 | xargs -0 rm -rf          /* remove the svn folder from project */

svn co     /* svn checkout */

svn ci -m 'commit'            /* commit the project */

svn up            /* update fron svn  */

svn st            /* check file in the project project which are not committed */

svn add *       /* add new file */

svn ci -m 'commit'            /* commit the project */

svn ci -m 'ciommit' folder_name/filename.php /* commit folder and file */

vim filename.php               /* for open file in online server */

i                        /* inset for online */

:wq!                   /* save and exit from file */
:q!          /* without save exit */

svn mkdir folder_name    /* Create folder name */

chmod -R 777 folder_name/       /* change folder permision */

mysql -u username -p database_name < file_name.sql    /* import database in mysql */

Tuesday, 11 August 2015

how to remove index.php from url in magento

1) Log-in to your Magento administration area then go to 'System > Configuration > Web'.
2) Navigate to the 'Unsecure' and 'Secure' tabs. Make sure the 'Unsecured' and 'Secure' - 'Base Url' options have your domain name within it, and do not leave the forward slash off at the end of the URL. Example:
3) While still on the 'Web' page, navigate to 'Search Engine Optimisation' tab and select 'YES' underneath the 'Use Web Server Rewrites' option.
4) Navigate to the 'Secure' tab again (if not already on it) and select 'Yes' on the 'Use Secure URLs in Frontend' option.
5) NoW go to the root of your Magento website folder and use this code for your .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Save the .htaccess and replace the original file. (PLEASE MAKE SURE TO BACKUP YOUR ORIGINAL .htaccess FILE BEFORE MESSING WITH IT!!!)
6) Now go to 'System > Cache Management'     refresh

logout  and enjoy.

Sunday, 9 August 2015

how to save div content as image using jquery


This script allows you to take "screenshots" of webpages or parts of it, directly on the users browser. The screenshot is based on the DOM and as such may not be 100% accurate to the real representation as it does not make an actual screenshot, but builds the screenshot based on the information available on the page.
Learn more »

Saturday, 8 August 2015

how to create categogories in magento or emport and export from database.

Category Creation in magento
Whenever you created category in magento then the created category info will be insert into following tables in magento
1. catalog_category_entity
2. catalog_category_entity_datetime
3. catalog_category_entity_decimal
4. catalog_category_entity_int
5. catalog_category_entity_text
6. catalog_category_entity_varchar
7. catalog_category_flat

remember if you want import category in magento so you simply these these table data export from another database and import whenever you want that its .