vikas
Vikas Pandey@vikas

I am the best

  • 5 years-11 months

    How to add the media uploader in wordpress plugin

    • Category : php
    • Location : Chandigarh, India
    • Posted On : Apr 18, 2016
    • Posted by : Vikas

    When i click the first upload field (uploading process are success) after insert into post that corresponding media url is appear in the second field not in first. I am not sure where is the problem any suggestion would be great.

    <?php
    wp_enqueue_script('jquery');
    // This will enqueue the Media Uploader script
    wp_enqueue_media();
    ?>
        <div>
        <label for="image_url">Image</label>
        <input type="text" name="image_url" id="image_url" class="regular-text">
        <input type="button" name="upload-btn" id="upload-btn" class="button-secondary" value="Upload Image">
     </div>
    <script type="text/javascript">
    
    jQuery(document).ready(function($){
        $('#upload-btn').click(function(e) {
            e.preventDefault();
            var image = wp.media({ 
                title: 'Upload Image',
                // mutiple: true if you want to upload multiple files at once
                multiple: false
            }).open()
            .on('select', function(e){
                // This will return the selected image from the Media Uploader, the result is an object
                var uploaded_image = image.state().get('selection').first();
                // We convert uploaded_image to a JSON object to make accessing it easier
                // Output to the console uploaded_image
                console.log(uploaded_image);
                var image_url = uploaded_image.toJSON().url;
                // Let's assign the url value to the input field
                $('#image_url').val(image_url);
            });
        });
    });
    </script>
    
    
    
    // UPLOAD ENGINE
    function load_wp_media_files() {
        wp_enqueue_media();
    }
    add_action( 'admin_enqueue_scripts', 'load_wp_media_files' );
     
  • 5 years-11 months

    .htaccess Tricks To Speed Up Your Website

    • Category : htaccess
    • Location : Chandigarh, India
    • Posted On : Dec 15, 2015
    • Posted by : Vikas

    Speed-up your website with these simple .htaccess tricks

    # Do not remove this line or mod_rewrite rules and search engine friendly URLs will stop working
    RewriteBase /
    
    # BEGIN Cache-Control Headers
    <ifModule mod_headers.c>
     <filesMatch ".(ico|jpe?g|png|gif|swf)$">
       Header set Cache-Control "public"
     </filesMatch>
     <filesMatch ".(css)$">
       Header set Cache-Control "public"
     </filesMatch>
     <filesMatch ".(js)$">
       Header set Cache-Control "private"
     </filesMatch>
     <filesMatch ".(x?html?|php)$">
       Header set Cache-Control "private, must-revalidate"
     </filesMatch>
    </ifModule>
    # END Cache-Control Headers
    
    <ifmodule mod_expires.c>
    <Filesmatch "\.(jpg|jpeg|png|gif|js|css|swf|ico|woff|mp3)$">
        ExpiresActive on
        ExpiresDefault A2592000
    </Filesmatch>
    </ifmodule>
    
  • 5 years-11 months

    how to post data using ajax

    • Category : php
    • Location : Chandigarh, India
    • Posted On : Dec 08, 2015
    • Posted by : Vikas

    1 Answers

    View More

    vikas image

    Name: vikas

    Experiance: 5 years-11 months

    answered
    Dec 08, 2015

    create file result.php

    <?php
    if( $_REQUEST["name"] ) {
    
       $name = $_REQUEST['name'];
       echo "Welcome ". $name;
    }
    
    ?>

    create your html file with this code

    <html>
    
       <head>
          <title>The jQuery Example</title>
          <script type = "text/javascript" 
             src = "http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
       
          <script type = "text/javascript" language = "javascript">
             $(document).ready(function() {
          
                $("#driver").click(function(event){
           
                   $.post( 
                      "result.php",
                      { name: "Zara" },
                      function(data) {
                         $('#stage').html(data);
                      }
                   );
             
                });
           
             });
          </script>
       </head>
     
       <body>
     
          <p>Click on the button to load result.html file %u2212</p>
        
          <div id = "stage" style = "background-color:cc0;">
             STAGE
          </div>
        
          <input type = "button" id = "driver" value = "Load Data" />
       
       </body>
      
    </html>

  • 5 years-11 months

    how to get zip to address

    • Category : php
    • Location : Chandigarh, India
    • Posted On : Dec 07, 2015
    • Posted by : Vikas

    1 Answers

    View More

    vikas image

    Name: vikas

    Experiance: 5 years-11 months

    answered
    Dec 07, 2015

    <?php
    class ZiptoAddress()
    {
    function getLnt($zip)
    {
    $url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$zip."&sensor=false";
    $result_string = file_get_contents($url);
    $result = json_decode($result_string, true);
    //$result1[]=$result['results'][0];
    //$result2[]=$result1[0]['geometry'];
    //$result3[]=$result2[0]['location'];
    //return $result[0];
    //return $result['results'][0]['geometry']['location'];
    return $result['results'][0];
    //print_r($result1[0]['formatted_address']);
    }
    }
    $val = getLnt('90001');
    echo "Address: ".$val['formatted_address']."<br>";
    echo "Latitude: ".$val['geometry']['location']['lat']."<br>";
    echo "Longitude: ".$val['geometry']['location']['lng']."<br>";
    ?>

     

  • 5 years-11 months

    explode an array php not working

    • Category : php
    • Location : Chandigarh, India
    • Posted On : Aug 14, 2015
    • Posted by : Vikas
    array(6) { 
    [0]=> string(0) "" 
    [1]=> string(21) " Subject Hello World " 
    [2]=> string(57) " Bonjour se jserais base sdf sdf sd f sqdf qsfd " 
    [3]=> string(22) " martial@gironde.com2 " 
    [4]=> string(12) " hello byee " 
    [5]=> string(11) " loul fund " } 
    
  • 5 years-11 months

    php explode not working correctly

    • Category : php
    • Location : Chandigarh, India
    • Posted On : Aug 14, 2015
    • Posted by : Vikas

    After wordpress login redirect page but not refresh so please try to add these lines in the top of the your wordpress theme file like header.php or wp-config.php https://www.youtube.com/watch?v=ItTjUrTZ_JE

    <?php
    str = "Hello world. It's a beautiful day.";
    print_r (explode(" "$str));
    ?>
    

    1 Answers

    View More

    vikas image

    Name: vikas

    Experiance: 5 years-11 months

    answered
    Aug 23, 2015

    error in 3rd line

    write this :

    <?php
    $a="how work php,wordpress";
    $b=explode(',',$a);
    print_r($b);
    // or 
    echo $b[0]; // $b[1]
    // output
    // $b[0] = how work php
    // $b[1] = wordpress
    ?>