Saturday, 21 December 2013

Widgets API

This page contains the technical documentation for the WordPress Widgets API and is written for developers. If you're not a developer you may want to review the Widgets page.
In technical terms: a WordPress Widget is a PHP object that echoes string data to STDOUT when its widget() method is called. It's located in wp-includes/widgets.php.

Codex

Function Reference/is active widget

Contents

[hide]

Description

This Conditional Tag checks whether widget is displayed on the front-end.
To be effective this function has to run after widgets have initialized, at action 'init' or later.

Usage

 <?php is_active_widget( $callback, $widget_id, $id_base, $skip_inactive ); ?> 

Parameters

$callback
(string) (optional) Widget callback to check.
Default: False
$widget_id
(int) (optional) Widget ID. Needed for checking.
Default: None
$id_base
(string) (optional) Base ID of a widget created by extending WP_Widget.
Default: None
$skip_inactive
(boolean) (optional) Whether to check in 'wp_inactive_widgets'.
Default: True

Return Values

(mixed) 
Returns false if the specified widget is not active, or the id of the sidebar in which the widget is active. If the callback is non-unique you can optionally specify the ID of the widget.

Examples

Only load a script when the widget is active

<?php
if ( is_active_widget( false, false, $this->id_base, true ) ) {
 wp_enqueue_script( 'jquery' );
}
?>

Change Log

Since: 2.2.0

Source File

is_active_widget() is located in wp-includes/widgets.php.

Friday, 20 December 2013

Remove side space in string


avascript Trim Functions

Use the code below to make trim a method of all Strings. These are useful to place in a global Javascript file included by all your pages.

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
    return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
    return this.replace(/\s+$/,"");
}

// example of using trim, ltrim, and rtrim
var myString = " hello my name is ";
alert("*"+myString.trim()+"*");
alert("*"+myString.ltrim()+"*");
alert("*"+myString.rtrim()+"*");

Javascript Trim Stand-Alone Functions

If you prefer not to modify the string prototype, then you can use the stand-alone functions below.

function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
    return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
    return stringToTrim.replace(/\s+$/,"");
}

// example of using trim, ltrim, and rtrim
var myString = " hello my name is ";
alert("*"+trim(myString)+"*");
alert("*"+ltrim(myString)+"*");
alert("*"+rtrim(myString)+"*");

Remove side space in string

What is the difference between plugins and widgets?


Plugins are functions that do something to your website. They could serve a back-end purpose and never be visible to you or the public. In the other hand, a widget usually is the representation of a plugin in the form of an object that can be placed somewhere on your website via the widgets interface under the appearance menu.

Widgets are always plugins, but plugins don’t always have widgets. A widget usually is a pretty and easy way of using a plugin. I hope this short explanation clears some things up if you’re just starting with WordPress.

What is the difference between plugins and widgets?
Plugins are functions that do something to your website. They could serve a back-end purpose and never be visible to you or the public. In the other hand, a widget usually is the representation of a plugin in the form of an object that can be placed somewhere on your website via the widgets interface under the appearance menu.
Widgets are always plugins, but plugins don’t always have widgets. A widget usually is a pretty and easy way of using a plugin. I hope this short explanation clears some things up if you’re just starting with WordPress.
- See more at: http://www.naveenos.com/2010/06/wordpress-widgets-vs-plugins-what%e2%80%99s-the-difference.html#sthash.2qRFRtPK.dpuf
What is the difference between plugins and widgets?
Plugins are functions that do something to your website. They could serve a back-end purpose and never be visible to you or the public. In the other hand, a widget usually is the representation of a plugin in the form of an object that can be placed somewhere on your website via the widgets interface under the appearance menu.
Widgets are always plugins, but plugins don’t always have widgets. A widget usually is a pretty and easy way of using a plugin. I hope this short explanation clears some things up if you’re just starting with WordPress.
- See more at: http://www.naveenos.com/2010/06/wordpress-widgets-vs-plugins-what%e2%80%99s-the-difference.html#sthash.2qRFRtPK.dpuf
What is the difference between plugins and widgets?
Plugins are functions that do something to your website. They could serve a back-end purpose and never be visible to you or the public. In the other hand, a widget usually is the representation of a plugin in the form of an object that can be placed somewhere on your website via the widgets interface under the appearance menu.
Widgets are always plugins, but plugins don’t always have widgets. A widget usually is a pretty and easy way of using a plugin. I hope this short explanation clears some things up if you’re just starting with WordPress.
- See more at: http://www.naveenos.com/2010/06/wordpress-widgets-vs-plugins-what%e2%80%99s-the-difference.html#sthash.2qRFRtPK.dpuf
What is the difference between plugins and widgets?
Plugins are functions that do something to your website. They could serve a back-end purpose and never be visible to you or the public. In the other hand, a widget usually is the representation of a plugin in the form of an object that can be placed somewhere on your website via the widgets interface under the appearance menu.
Widgets are always plugins, but plugins don’t always have widgets. A widget usually is a pretty and easy way of using a plugin. I hope this short explanation clears some things up if you’re just starting with WordPress.
- See more at: http://www.naveenos.com/2010/06/wordpress-widgets-vs-plugins-what%e2%80%99s-the-difference.html#sthash.2qRFRtPK.dpuf

WordPress Widgets vs Plugins, what’s the difference?

June 15, 2010 | In: Wordpress
What is the difference between plugins and widgets?
Plugins are functions that do something to your website. They could serve a back-end purpose and never be visible to you or the public. In the other hand, a widget usually is the representation of a plugin in the form of an object that can be placed somewhere on your website via the widgets interface under the appearance menu.
Widgets are always plugins, but plugins don’t always have widgets. A widget usually is a pretty and easy way of using a plugin. I hope this short explanation clears some things up if you’re just starting with WordPress.
- See more at: http://www.naveenos.com/2010/06/wordpress-widgets-vs-plugins-what%e2%80%99s-the-difference.html#sthash.B7nYeAxf.dpuf

WordPress Widgets vs Plugins, what’s the difference?

June 15, 2010 | In: Wordpress
What is the difference between plugins and widgets?
Plugins are functions that do something to your website. They could serve a back-end purpose and never be visible to you or the public. In the other hand, a widget usually is the representation of a plugin in the form of an object that can be placed somewhere on your website via the widgets interface under the appearance menu.
Widgets are always plugins, but plugins don’t always have widgets. A widget usually is a pretty and easy way of using a plugin. I hope this short explanation clears some things up if you’re just starting with WordPress.
- See more at: http://www.naveenos.com/2010/06/wordpress-widgets-vs-plugins-what%e2%80%99s-the-difference.html#sthash.B7nYeAxf.dpuf

Monday, 7 October 2013

Custom Short Code Creation

Add this Short Code function in main plugin file


add_shortcode('love', 'fun_love');
function fun_love()
{ 
    include "fun_love.php"; //include out put file in this function
}



function validate()
{
    var delete_data=confirm("Do you really want to delete this row?");
    if(delete_data==false)
    {
        return false;
    }
    else
    {
        return true;
    }
}

</script>

</head>

<body>
<div class="wrap">
     global $wpdb;
     $url = admin_url( 'admin.php?page=add-love', '' );
     $url2 = admin_url('admin.php?page=love/love_table.php', '');
   
     $table_name = $wpdb->prefix . "tbllove";
   

$query="SELECT * FROM $table_name  ";
     $row=$wpdb->get_results($query);
   
     //Get Admin Page parent
   
     //$a=get_admin_page_parent();
     //echo "<br/>"."Admin Page parent is :".$a."<br/>";
   
     //Get Plugin URL
   
     //$plugins_url = plugins_url();
     //echo "<br/>"."Plugin URL : ".$plugins_url."<br/>";
   
     //Get Admin URL
   
     //$adminurl=get_admin_url();
     //echo "<br/>"."Admin URL : ".$adminurl;
   
     ?>
   
     <table width='600' border='1' class='widefat'>
     <thead>
          <tr>
             <th>Id</th>
             <th>Name</th>
             <th>Image</th>
             <th>Junder</th>
             <th>Love_id</th>
             <th>With_love</th>
        </tr>
     </thead>
    
     <tr>
     <?php
   
     foreach ( $row as $row1 )
     {
    // $upload_dir=wp_upload_dir();
     $TARGET_PATH="/wp-content/uploads/love_images/";
    //echo $TARGET_PATH.$row1->image;
    $path=get_site_url().$TARGET_PATH;
     //echo plugins_url('love/upload/');
         $id=$row1->id;
     ?>
        <td><?php echo $row1->id; ?></td>
         <td><?php echo $row1->Name; ?></td>
        <td><img src="<?php echo $path.$row1->image; ?>" width="40" height="40"/></td>
        <td><?php echo $row1->Junder; ?></td>
        <td><?php echo $row1->love_id; ?></td>
        <td><?php echo $row1->With_love; ?></td>
          
     
    </tr>
        <input name='id' type='hidden' value='$id'/>
    <?php
     }
    ?>
     </table>

    </div>
</body>
</html>

Wednesday, 28 August 2013

How to Increase Site Speed

How to Increase Site Speed

Fighting Google Panda, we made our site faster, and worked to increase site speed. Site speed and page load times are now an important component of the Google ranking algorithm, which can affect search engine rankings of your site. Since our site was affected with Google Panda, we have been striving to make our site faster for a better user experience. At one time, our site was slower than 94% of all sites on the web!
 Increase Site Speed

So here is what all we did and you can also try to improve page load times. Before starting out, test the page speed of your homepage and different article pages, so later you can see the difference.

1. Use Caching plugin -  this is the single most important plugin to reduce server load and increase site speed, as it caches your pages as html files and speeds page delivery to browser, minimizing WordPress php calls. We have been using WP-Supercache for many years and now trying QuickCache which is equally good, and simpler. W3-TotalCache is also a popular alternative.

2. Use CDN – we have been using Amazon Cloudfront for quite some time and it is an excellent CDN (Content Delivery Network) which we use to offload our static resources like CSS, javascripts and theme images to reduce load on our server. This makes the site faster. MaxCDN is another popular CDN which when combined with TotalCache can send your entire site to a CDN system with compression for ultra fast loading.

3. Reduce sidebar / Footer clutter -  earlier there were several sidebar widgets, images etc which loaded everytime and slowed the pages, they are now reduced a basic minimal links and BSA ads in the sidebar. If you look around your site theme, you will find many irrelevant widgets loading everytime, and they add to lot of site load time. Remove them for a cleaner website design. We in addition added a responsive web design to make our site compatible on many mobile devices.

4. Remove Related Widgets –  we have been using the amazing YARPP related posts plugin to deliver the related links you see at the bottom of all posts. In addition we used to use the amazing Outbrain widget to generate related posts thumbnails. Both have their own load times, and we decided to remove Outbrain and continue with YARRP, which still uses a load of server processing power (as tested by P3 - Plugin Performance Profiler), and I am looking for a faster alternative (any suggestions?). We earlier used Google related links which was better with much less load time, but it was shut down by Google.

5. Reduce Social Buttons –  these are a big drag on site load time, as enhanced functionality is making their javascript files larger which take longer to load. We used the excellent Sharebar plugin to load many social sharing buttons in the sidebar, but that loads up many scripts and takes longer to load. Then we decided to keep only the few popular sharing buttons like Facebook, Twitter and Google plus one (which might impact search results some day!). Each of these has large scripts to load. If you decide to reduce the buttons you can try AddThis, but with interactive buttons, it too will load all these scripts contributing to load times. Also if you decide to add them before and after the post, it will lead to more sharing, but also slower speed.

6. Avoid Extra Comment Systems – Comment systems load huge scripts, large number of files and add to load time. There are some amazing comment systems out there like Disqus, IntenseDebate, LiveFyre and Facebook Comments. WordPress own comments system is the lightest to load and rest all will slow site speed. But then we continue to use Facebook comments, though it significantly adds to our page loading times, as posted comments are often posted to Facebook user walls and brings extra traffic.

7. Disable Gravatars -  We used to used to host Gravatars with comments earlier. They look nice, and encourage more comments undoubtedly, but then those 100 comments on your popular page will also load 100  gravatars! So disabling gravatars, will speed up site comments loading.

8. Load less Comments –  We don’t allow 100 comments to be loaded on any page. If you see only 5 comments load on our pages, and rest are paginated if users want to read more comments. We also disabled threading as it loaded more scripts for response to replies. This does lead to reduced comments but makes the site faster. Use WordPress comment options (Settings>Discussion) to reduce comments on pages as per your need. Though Akismet does a great job at stopping spam comments, we also turned off comments on older posts, to minimize spam attempts.

9. Javascripts at bottom, minimize, compress – Its a good idea to shift all javascripts to the footer so that they don’t interfere with site loading. Some exceptions are the modern asynchronous scripts which can be added higher in the code and load beside your site without slowing it e.g. Google recommends you load Analytics in the HEAD tags. You can also try to combine javascripts and compress them for faster loading. Always load CSS in the HEAD and minimize CSS too, and of course CDN is better. There are many plugins which can also do this.

10 Reduce Images and their sizes – we always try to keep our image sizes low, save in lesser colors and at times it does reduce image quality, but leads to faster loading images. It is also important to load as few images as possible per page. Better still to offload them to a CDN. Though we dont use it, many recommend plugins like Smush-it which will compress images on your server. You can even try CSS Sprites to combine images. Also always remember to specify image dimensions.

11. Leverage Browser caching –  A simple htaccess trick will make modern web browsers cache static resources and deliver them faster. Try Browser caching and you will immediately appreciate the overall difference for repeat visitors.

12. Embed Less Videos – we observed that in posts where we embedded many Youtube videos, the site load times were highest. In case that is your most popular post too, then most visitors get the slowest page speed. So reduce the number of embedded videos and see the site speed increase.

13. GZip Compression On – Modern browsers accept compressed versions of webpages and allow faster page delivery to the user. We are using QuickCache now and a simple php.ini tweak made our server deliver gzip compressed pages. WP-Supercache has an easy option to check and enable gzip.


 We hope you follow some of these tips and make your site faster. Share with your friends and post your tips in comments.

Sunday, 21 July 2013

jQuery ajax

jQuery(document).ready(function () {
/*jQuery("#modaltrigger").click(function() {
alert("Handler for .click() called.");*/
jQuery('#my_email').click(function () {
var email = jQuery('#my_email').val();
    //alert(email);
 <?php $url = plugin_dir_path( __FILE__ ); ?>
    jQuery.ajax({
            type: 'POST',
            url:'http://192.168.1.44/fan/validate.php',
            data: {email: email},
            success: function(data) {
               // jQuery("#load").append("<h2>you are here</h2>");
               alert(data);
            //jQuery("#load").innerHTML(data);
            jQuery('#load').append(data);
            //jQuery('#load').val(data); 
            }       
       
        });
   
});

});

Thursday, 6 June 2013

Mail sending through wordpress

><?php
>$url = $_SERVER['HTTP_HOST'].'/~esmesqui/wp-load.php';
>require_once('../../../wp-load.php');
>?>
><?php ob_start();
>$con=mysqli_connect("localhost","root","","esmesqui_ems_db");
>if (mysqli_connect_errno($con))
>{
> echo "Failed to connect to MySQL: " . mysqli_connect_error();
>}
>else
>{
> if($_POST['name1']!="")
> {
>
> $name=trim($_POST['name1']);
> $email=trim($_POST['email1']);
> $subject_name=trim($_POST['subject_name1']);
> $msg=($_POST['msg1']);
> $param=$name."<br/>".$email."<br/>".$subject_name."<br/>".$msg;
> $sql="INSERT INTO wp_contact(contact_name,contact_subject,contact_email,contact_msg) VALUES('".$name."','".$subject_name."','".$email."','".$msg."')";
> $headers = "From:" . $email;
> wp_mail('kgaidhane@rediffmail.com','Contact From esmesquire.com',$param,$headers);
>   if(wp_mail('kgaidhane@rediffmail.com','Contact FROM esmesquire.com',$param,$headers))
>   {
> //echo "mail sent";
> header('Location: ' . $_SERVER['HTTP_REFERER'].'?id=2');
>   }
>   else
>   {
> echo "mail failed";
>   }
>
>
> if (!mysqli_query($con,$sql))
>  {
>  die('Error: ' . mysqli_error($con));
>  }
>          
>        header('Location: ' . $_SERVER['HTTP_REFERER'].'?id=2');
> }
> else if($_POST['name2']!="")
> {
> $name=trim($_POST['name2']);
> $email=trim($_POST['email2']);
> $subject_name=trim($_POST['subject_name2']);
> $msg=($_POST['msg2']);
> $param=$name."<br/>".$email."<br/>".$subject_name."<br/>".$msg;
> $sql="INSERT INTO wp_contact(contact_name,contact_subject,contact_email,contact_msg) VALUES('".$name."','".$subject_name."','".$email."','".$msg."')";
> $headers = "From:" . $email;
> wp_mail('kgaidhane@rediffmail.com','Contact From esmesquire.com',$param,$headers);
>   if(wp_mail('kgaidhane@rediffmail.com','Contact FROM esmesquire.com',$param,$headers))
>   {
> echo "mail sent";
>   }
>   else
>   {
> echo "mail failed";
>   }
> if (!mysqli_query($con,$sql))
>  {
>  die('Error: ' . mysqli_error($con));
>  }
>          
>        header('Location: ' . $_SERVER['HTTP_REFERER'].'?id=2');
> }
>
>  else if($_POST['name3']!="")
> {
> $name=trim($_POST['name3']);
> $email=trim($_POST['email3']);
> $subject_name=trim($_POST['subject_name3']);
> $msg=($_POST['msg3']);
> $param=$name."<br/>".$email."<br/>".$subject_name."<br/>".$msg;
> $sql="INSERT INTO wp_contact(contact_name,contact_subject,contact_email,contact_msg) VALUES('".$name."','".$subject_name."','".$email."','".$msg."')";
> $headers = "From:" . $email;
> wp_mail('kgaidhane@rediffmail.com','Contact From esmesquire.com',$param,$headers);
>   if(wp_mail('kgaidhane@rediffmail.com','Contact FROM esmesquire.com',$param,$headers))
>   {
> echo "mail sent";
>   }
>   else
>   {
> echo "mail failed";
>   }
>
> if (!mysqli_query($con,$sql))
>  {
>  die('Error: ' . mysqli_error($con));
>  }
>          
>        header('Location: ' . $_SERVER['HTTP_REFERER'].'?id=2');
> }        
>}
>?>