helper tab in wordpress

Helper tab in wordpress

 
 /*
  * helper class for all admin pages 
  */
class my_wp_helper_class { 
    public function __construct() {
        if (defined('WP_ADMIN') && WP_ADMIN) {
            global $page_hook;
            $this->current_screen = get_current_screen(); 
            if (method_exists($this, $page_hook)) {
                add_action("load-".$page_hook,array($this,$page_hook)); 
            }  
        }
    }

    /*  To add helper tab 
     * Accept the array in $args default is shown below
     * $defaults = array('title'    => false,'id'=> false,'content'  => '','callback' => false);  
     */
    protected function add_help_tab($args) {
         $this->current_screen->add_help_tab($args);
    }
    /*
     * accept the string in $content args
     * $content =" sample content";
     */
    protected function set_help_sidebar($content) { 
         $this->current_screen->$args($content);
    }

    public function plugin_page_my_page() {   // function name must be $page_hook name echo the $page_hook in the __construct() 
        $options_help = 'helper message for tab1';
        $this->add_help_tab(array(
								'id' => 'tab1',
								'title' => __('tab1'),
								'content' => $options_help,
							));

        $options_help2 = 'helper message for tab2';

        $this->add_help_tab(array(
								'id' => 'tab2',
								'title' => __('tab2'),
								'content' => $options_help2,
							)); 
	     $this->set_help_sidebar("side bar content");
	}

}

add_action('current_screen', create_function('', 'new my_wp_helper_class;'));

ajax file upload

ajax file upload

 
<html>
  <head>
    <title> file upload script in ajax </title>
    <script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.js'></script>
  </head>
  <body>
    <form name="comp_logo" id="comp_logo" method="POST" action="" enctype="multipart/form-data">
      <input type="file" name="add_logo" id="upload_file" class="add_logo">
      <input type="button" class="upload_logo" value="upload"><br>
    </form>
    <div>
        you must add a file upload script in http://example.com/admin/admin-ajax.php php :<a href="http://www.w3schools.com/php/php_file_upload.asp"> upload script </a>
    </div>
    <script type="text/javascript">
      jQuery(document).ready(function(){
        jQuery('.upload_logo').click(function(){
          var fd = new FormData(); // form data object
          fd.append( 'file', jQuery( '#upload_file' )[0].files[0] ); // add the file to the form data
          fd.append( 'action', 'obs_update_comp_logo'); // add the extra paramater to the form data object

          // Ajax call
          jQuery.ajax({
            data: fd, // data send with file
            processData: false,
            contentType: false,
            type: 'POST',
            async: false,
            url:'http://example.com/admin/admin-ajax.php',
            success: function(res){
                alert("file uploaded !!!")
                 /* sucess function */
            }
          });
          return false; // to stop the process
        });
     });
    </script>
  </body>
</html>

geo location of current user in javascript

get the current geo location in the in the javascript

save this file & check

<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to get your coordinates:</p>
<button onclick="getLocation()">getLocation</button>
<button onclick="watchLocation()">Watch location </button>
<script>
var x=document.getElementById("demo");
var id, target, option;
options = {
enableHighAccuracy: false,
timeout: 5000,
maximumAge: 0
};

target = {
latitude : 0,
longitude: 0,
}

function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition,showError,options);
}
else{x.innerHTML="Geolocation is not supported by this browser.";}
}

function showPosition(position)
{
console.log(position);
x.innerHTML="Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}

function watchLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.watchPosition(success_watch,showError,options);
}
else{x.innerHTML="Geolocation is not supported by this browser.";}
}

function success_watch(position) {
var crd = position.coords;
x.innerHTML="Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;
if (target.latitude === crd.latitude && target.longitude === crd.longitude) {
console.log('Congratulation, you reach the target');
navigator.geolocation.clearWatch(id);
}
};

function showError(error)
{
console.log('ERROR('+error.code + '): ' + error.message);
switch(error.code)
{
case error.PERMISSION_DENIED:
x.innerHTML="User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML="Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML="The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML="An unknown error occurred."
break;
}
}

</script>
</body>
</html>