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>

get the object to array format in php

get the object to array format in php

<?php
class Point2D {
var $x, $y;

function Point2D($x, $y)
{
$this->x = $x;
$this->y = $y;
}

}

$p1 = new Point2D(1.233, 3.445);
echo “<pre>”;
print_r($p1);   //print in object formate
echo “</pre>”;

echo “<pre>”;
print_r(get_object_vars($p1));   //print in array format
echo “</pre>”;

?>

_______________________________________________________________________________________

// ******************Output**********************************************

_______________________________________________________________________________________

Point2D Object
(
[x] => 1.233
[y] => 3.445
[label] =>
)
Array
(
[x] => 1.233
[y] => 3.445
[label] =>
)