Pages

Tuesday, March 26, 2013

Add HTML tags to widget title [ wordpress ] - resolved


If you want to add HTML tags to widget tile then please write below code in "functions.php"
<?php
function html_widget_title( $title ) {
 //HTML tag opening/closing brackets
 $title = str_replace( '[', '<', $title );
 $title = str_replace( '[/', '</', $title );

 //<span></span>
 $title = str_replace( 'span]', 'span>', $title );

 return $title;
}
add_filter( 'widget_title', 'html_widget_title' );
?>

Example:       
[span]Your Text[/span]

Monday, March 25, 2013

Cycle slider with Previous - next effect - resolved


<script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="js/jquery.cycle.all.js"></script>

<script type="text/javascript">
$(document).ready(function() {
    $('.slideshow').cycle({ 
    fx:     'scrollRight', 
    speed:  'fast', 
 next:   '#next2', 
    prev:   '#prev2',
 timeout:       0, 
 pause:         1,     // true to enable "pause on hover" 
    pauseOnPagerHover: 1,
    pager:  '#navNew', 
    pagerAnchorBuilder: function(idx, slide) { 
        // return selector string for existing anchor 
        return '#navNew li:eq(' + idx + ') a'; 
    } 
});
});
</script>

Twitter Feed Widget


<script src="http://widgets.twimg.com/j/2/widget.js"></script>

<script>
new TWTR.Widget({
      version: 2,
      type: 'profile',
      rpp: 4,
      interval: 4000,
      width: 'auto',
      height: 150,
      theme: {
         shell: {
         background: '#3b3b3b',
         color: '#000000'
       },
      tweets: {
         background: '#ffffff',
         color: '#000000',
         links: '#0707eb'
      }
   },
   features: {
      scrollbar: false,
      loop: true,
      live: false,
      hashtags: true,
      timestamp: true,
      avatars: false,
      behavior: 'default'
   }
}).render().setUser('username').start();
</script>

Monday, March 18, 2013

Hide other shipping methods when FREE SHIPPING is available - woocommerce



// Hide standard shipping option when free shipping is available
add_filter( 'woocommerce_available_shipping_methods', 'hide_standard_shipping_when_free_is_available' , 10, 1 );

/**
* Hide Standard Shipping option when free shipping is available
*
* @param array $available_methods
*/
function hide_standard_shipping_when_free_is_available( $available_methods ) {

if( isset( $available_methods['free_shipping'] ) AND isset( $available_methods['flat_rate'] ) ) {

// remove standard shipping option
if( isset( $available_methods['free_shipping'] ) ) {
$freeShipping = $available_methods['free_shipping'];
unset( $available_methods );

$available_methods['free_shipping'] = $freeShipping;
}
return $available_methods;
}

return $available_methods;
}

Wednesday, March 13, 2013

Wordpress add & remove script from head setion - resolved



add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );

function my_deregister_javascript() {
wp_deregister_script( 'plugin-shortcode' ); /*wp_deregister_script( 'ad-gallery' );*/
}

function my_scripts_method() {
wp_enqueue_script('custom-script',get_template_directory_uri() . '/js/yourscript.js',array('jquery') );
wp_register_style( 'custom-style', get_template_directory_uri() . '/css/yourcustom.css');
wp_enqueue_style( 'custom-style' );
}
add_action('wp_enqueue_scripts', 'my_scripts_method');

Friday, March 8, 2013

woocommerce redirect user to cart page after click on add to cart



Please write this code in functions.php file in wordpress theme

add_filter('add_to_cart_redirect', 'custom_add_to_cart_redirect');

function custom_add_to_cart_redirect() {
     return get_permalink(get_option('woocommerce_cart_page_id')); // Replace with the url of your choosing
}

Wednesday, March 6, 2013

Add wordpress post from front-end with featured images and send mail [resolved]


/*Create Form*/

<form class="story" name="share_story" action="" method="POST"  id="story_form" enctype="multipart/form-data">
    <label>Name</label><br />
    <input type="text" class="flat_input_box" name="share_name" id="share_name" /><br />  
    <label>Email address</label><br />
    <input type="text" class="flat_input_box" name="share_email_address" id="email_address" /><br />  
    <label>Upload Image</label><br />
    <input type="file" name="story_image" class="flat_input_box" id="featured_image" /><br />
    <label>Story Title</label><br />
    <input type="text" class="flat_input_box" name="story_title" id="story_title" /><br />
    <textarea class="flat_input_box" name="story_content" id="story_content"></textarea><br />  
    <div class="right">
        <a href="#">Cancel</a>
     <input class="blue_btn" type="submit" value="Submit" onclick="return CheckStoryForm();" name="submit" />
    </div>
</form>

/*Create Form */

/*Javascript validation Starts*/

<script>
function CheckStoryForm(){
var result = true;
var emailcheck = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var emailval = document.share_story.email_address.value;
if(document.share_story.name.value==''){
alert("Please enter name");
return false;
}
if(document.share_story.email_address.value==''){
alert("Please enter email address");
return false;
}
else if(!emailcheck.test(emailval))
{
alert('Please enter valid email address');
return false;
}

var fup = document.getElementById('featured_image');
var fileName = fup.value;
if(fileName != ''){
var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
if(ext == "gif" || ext == "GIF" || ext == "JPEG" || ext == "jpeg" || ext == "jpg" || ext == "JPG" || ext == "png" || ext == "PNG")
{
return true;
}
else{
alert("Please upload image with jpg, png, gif, jpeg formate.");
fup.focus();
return false;
}
}
if(document.share_story.story_title.value==''){
alert("Please enter title of story");
return false;
}

return true;
}
</script>

/*Javascript validation Ends*/


/*Post Submission Starts*/
if(isset($_POST['submit'])){

$name = $_POST['share_name'];
$email_address = $_POST['share_email_address'];
$story_title = $_POST['story_title'];
$story_content = $_POST['story_content'];
$admin_email = get_settings('admin_email');

/*custom post type*/
$new_post = array(
'post_title' => $story_title,
'post_content' => $story_content,
'post_status' => 'private',           // Choose: publish, preview, future, draft, etc.
'post_type' => 'share_your_story'  //'post',page' or use a custom post type if you want to
);
$pid = wp_insert_post($new_post);
/*custom post type*/

/*create and upload featured image with multiple resolution*/
$MyImage = '';
if(!empty($_FILES['story_image']['name'])){

include("simpleImage.php");  // please check http://ewebsurf.blogspot.in/2013/03/simpleimagephp.html from here you can copy the code of this file

$uploaddir = wp_upload_dir(); // get wordpress upload directory
$myDirPath = $uploaddir['path'];
$myDirUrl = $uploaddir['url'];

$MyImage = rand(0,5000).$_FILES['story_image']['name'];
$image_path = $myDirPath.'/'.$MyImage;
copy($_FILES['story_image']['tmp_name'],$image_path);

list($width, $height, $type, $attr) = getimagesize($myDirUrl.'/'.$MyImage); // get image property

$image = new SimpleImage();

$large_width = get_option('large_size_w');    // get large image resolution set as admin panel
$large_height = get_option('large_size_h');
if($width > $large_width || $height > $large_height){

$dimensions = fw_get_dimension_new($image_path, $large_width, $large_height);
$largeimage = $image_path;
$info = pathinfo($largeimage);
$image_name =  basename($largeimage,'.'.$info['extension']);
$ext = end(explode('.', $largeimage));
$newlargeimg = $myDirPath.'/'.$image_name.'-'.$dimensions['width'].'x'.$dimensions['height'].'.'.$ext;
copy($image_path,$newlargeimg);

            $image->load($newlargeimg);
            $image->resize($dimensions['width'],$dimensions['height']);
            $image->save($newlargeimg);
}

$medium_width = get_option('medium_size_w');
$medium_height = get_option('medium_size_h');

if($width > $medium_width || $height > $medium_height){

$dimensions = fw_get_dimension_new($image_path, $medium_width, $medium_height);
$mediumimage = $image_path;
$info = pathinfo($mediumimage);
$image_name =  basename($mediumimage,'.'.$info['extension']);
$ext = end(explode('.', $mediumimage));
$newmediumimg = $myDirPath.'/'.$image_name.'-'.$dimensions['width'].'x'.$dimensions['height'].'.'.$ext;
copy($image_path,$newmediumimg);

            $image->load($newmediumimg);
            $image->resize($dimensions['width'],$dimensions['height']);
            $image->save($newmediumimg);
}

$thumb_width = get_option('thumbnail_size_w');
$thumb_height = get_option('thumbnail_size_h');

if($width > $thumb_width || $height > $thumb_height){

$dimensions = fw_get_dimension_new($image_path, $thumb_width, $thumb_height);
$thumbimage = $image_path;
$info = pathinfo($thumbimage);
$image_name =  basename($thumbimage,'.'.$info['extension']);
$ext = end(explode('.', $thumbimage));
           
$ImageCrop = get_option('thumbnail_crop');
if($ImageCrop == 1){
$newthumbimg = $myDirPath.'/'.$image_name.'-150x150.'.$ext;
copy($image_path,$newthumbimg);

$image->load($newthumbimg);
$image->resize($thumb_width,$thumb_height);
} else {
$newthumbimg = $myDirPath.'/'.$image_name.'-'.$dimensions['width'].'x'.$dimensions['height'].'.'.$ext;
copy($image_path,$newthumbimg);

$image->load($newthumbimg);
$image->resize($dimensions['width'],$dimensions['height']);
}
            $image->save($newthumbimg);
}


$file = $MyImage;
$uploadfile = $myDirPath.'/' . basename( $file );
$filename = basename( $uploadfile );
$wp_filetype = wp_check_filetype(basename($filename), null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', $filename),
'post_content' => '',
'post_status' => 'inherit',
'post_parent' => $pid
);
$attach_id = wp_insert_attachment( $attachment, $uploadfile );

require_once(ABSPATH . "wp-admin" . '/includes/image.php');
$attach_data = wp_generate_attachment_metadata( $attach_id, $uploadfile );
wp_update_attachment_metadata( $attach_id,  $attach_data );

set_post_thumbnail( $pid, $attach_id );

}

$to = "Your Email Address";
$subject = " New Story ";
$headers = "From: $name <$email_address>\r\n";
$headers .= "MIME-Version: 1.0\r\n"."Content-Type: multipart/mixed; boundary=\"1a2a3a\"";

$message .= "If you can see this MIME than your client doesn't accept MIME types!\r\n"."--1a2a3a\r\n";

$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n";
$message .= '<table>';
$message .= '<tr><td><b>Name</b></td><td>'.$name.'</td></tr>';
$message .= '<tr><td><b>Email</b></td><td>'.$email_address.'</td></tr>';
$message .= '<tr><td><b>Story Title</b></td><td>'.$story_title.'</td></tr>';
$message .= '<tr><td colspan="2"><b>Content</b></td></tr>';
$message .= '<tr><td colspan="2">'.nl2br($story_content).'</td></tr>';
$message .= '</table>';
$message .= "\r\n"."--1a2a3a\r\n";

if($image != ''){
$file = file_get_contents($image_path);

$message .= "Content-Type: image/jpg; name=\"featuredimage.jpg\"\r\n"
  ."Content-Transfer-Encoding: base64\r\n"
  ."Content-disposition: attachment; file=\"$MyImage\"\r\n"
  ."\r\n"
  .chunk_split(base64_encode($file))
  ."--1a2a3a--";
}

if (mail($to, $subject, $message, $headers)) {
echo '<script>document.location="'.get_permalink().'/?msg=1";</script>';
} else {
echo '<script>document.location="'.get_permalink().'/?msg=2";</script>';
}


}

/*Post Submission Ends*/



SimpleImage.php


<?php

ini_set('memory_limit', '128M');

class SimpleImage {
 
   var $image;
   var $image_type;

   function load($filename) {
 
      $image_info = getimagesize($filename);
      $this->image_type = $image_info[2];
      if( $this->image_type == IMAGETYPE_JPEG ) {
         $this->image = imagecreatefromjpeg($filename);
      } elseif( $this->image_type == IMAGETYPE_GIF ) {
         $this->image = imagecreatefromgif($filename);
      } elseif( $this->image_type == IMAGETYPE_PNG ) {
         $this->image = imagecreatefrompng($filename);
      }
   }
   function save($filename, $image_type=IMAGETYPE_JPEG, $compression=85, $permissions=null) {
      if( $image_type == IMAGETYPE_JPEG ) {
         imagejpeg($this->image,$filename,$compression);
      } elseif( $image_type == IMAGETYPE_GIF ) {
         imagegif($this->image,$filename);        
      } elseif( $image_type == IMAGETYPE_PNG ) {
         imagepng($this->image,$filename);
      }  
      if( $permissions != null) {
         chmod($filename,$permissions);
      }
   }
   function output($image_type=IMAGETYPE_JPEG) {
      if( $image_type == IMAGETYPE_JPEG ) {
         imagejpeg($this->image);
      } elseif( $image_type == IMAGETYPE_GIF ) {
         imagegif($this->image);        
      } elseif( $image_type == IMAGETYPE_PNG ) {
         imagepng($this->image);
      }  
   }
   function getWidth() {
      return imagesx($this->image);
   }
   function getHeight() {
      return imagesy($this->image);
   }
   function resizeToHeight($height) {
      $ratio = $height / $this->getHeight();
      $width = $this->getWidth() * $ratio;
      $this->resize($width,$height);
   }
   function resizeToWidth($width) {
      $ratio = $width / $this->getWidth();
      $height = $this->getheight() * $ratio;
      $this->resize($width,$height);
   }
   function scale($scale) {
      $width = $this->getWidth() * $scale/100;
      $height = $this->getheight() * $scale/100;
      $this->resize($width,$height);
   }
   function resize($width,$height) {
 
      $new_image = imagecreatetruecolor($width, $height);
      imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
      $this->image = $new_image;  
   }    
}



function fw_get_dimension_new($src, $width = '', $height = '')
{

    // Convert width/height to int for proper validation.
    // intval() used to support compatibility with plugins like image-handler
    $width = empty($width) ? $width : intval($width);
    $height = empty($height) ? $height : intval($height);

// alt is added to the img tag even if it is null to prevent browsers from outputting
// the image filename as default

    if ($width != '' && $height != '' and file_exists($src))
{

 $image_size = @getimagesize($src);

 $ratio = ($image_size[0] != 0 ? $width / $image_size[0] : 1);
 if ($image_size[1]*$ratio > $height) {
$ratio = $height / $image_size[1];
$width = $image_size[0] * $ratio;
 } else {
$height = $image_size[1] * $ratio;
 }
// only use proportional image when image is larger than proportional size
 if ($image_size[0] < $width and $image_size[1] < $height) {
$width=$image_size[0];
$height=intval($image_size[1]);
 } else {
$width=round($width);
$height=round($height);
 }
    }

    $output['width'] = $width;
    $output['height'] = $height;

    return $output;
  }
 

/* how to use example by harikrishna
$file = "../images/save.png";
$dimensions = fw_get_dimension_new($file,'10','10');

$image = new SimpleImage();

$image->load($file);
$image->resize($dimensions['width'],$dimensions['height']);
$image->save($file);
*/
?>

Friday, March 1, 2013

Disable plugin upgrade warning in wordpress?

If you want to disabled plugin upgrade warning from admin pane than please add below wordpress hook into your functions.php file



function filter_plugin_updates( $value ) {
    unset( $value->response['PLUGIN-DIR/MAIN-PLUGINFILE-NAME'] );
    return $value;
}
add_filter( 'site_transient_update_plugins', 'filter_plugin_updates' );

EX:



function filter_plugin_updates( $value ) {
    unset( $value->response['all-in-one-seo-pack/all_in_one_seo_pack.php'] );
    return $value;
}
add_filter( 'site_transient_update_plugins', 'filter_plugin_updates' );