How to add an extra parameters in Visual Composer

Hello everyone

If you need to add an extra parameter to standard visual composer elements, you can do it in a few steps:

1. First, you need to attache your own function to a visual composer hook your own function, the visual composer hook is – vc_after_init. You need to write a code like this:

add_action( 'vc_after_init', 'vc_after_init_actions' );

Where vc_after_init_actions() must be your function name.

2. Secondly you need to create your function where you will set new parameters for standard elements:

function vc_after_init_actions() { 

    $new_args = array(
      array(
       'type' => 'dropdown',
       'heading' => __( 'Column type', 'js_composer' ),
       'param_name' => 'column_type',
       'value' => array(
         'Content column' => 'content_column',
         'Sidebar_column' => 'sidebar_column',
       ),
       'description' => '',
     )
   );
   vc_add_params('vc_column',$new_args);
}

In the code above I have used standard field settings which you can use in vc_map() function and I added this settings array to standard element settings with vc_add_params() function. After that you add these line codes to your project, you can see your defined field in the settings of a standard element in the admin panel.

Also you can remove fields from element settings with function vc_remove_param(). For example:

 vc_remove_param( 'vc_row', 'full_width' );

How to set limit of input file field with jQuery

Hello everyone!

By default in current implement of HTML in modern browsers input tag doesn’t support limit for uploaded files.
And if you need to set limit of maximum upload files in your field:

<input type="file" name="photos" multiple />

you can use simple jQuery snippet:

$(document).ready(function(){
	var limit_of_files = 5;
	$('input[type="file"]').on('change',function(){

		if($(this).prop('files').length>limit_of_files)
		{
			alert('You exceeded limit for uploading files! Maximum of uploading files is 5!');
			$(this).val('');
			return false;
		}

	});
});

How to delete zero byte files in your folders

It is easy peasy like this:

find . -type f -name "*.php" -size 0 -print0 | xargs -0 rm

And that’s all!


Disable woocommerce product gallery metabox

It is very simply remove this metabox with follow code:

add_action( 'add_meta_boxes' , 'remove_my_meta_boxes', 40 );
function remove_my_meta_boxes()
{
    remove_meta_box( 'woocommerce-product-images',  'product', 'side');
}

How to decode address to coordinates with Google maps api

Hello

For do this simple operation you need implement next function:

function  address_func(addresses, callback) {
        var coords = [];
        for(var i = 0; i < addresses.length; i++) {
            currAddress = addresses[i];
            var geocoder = new google.maps.Geocoder();
            if (geocoder) {
                geocoder.geocode({'address':currAddress}, function (results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        coords.push(results[0].geometry.location);
                        if(coords.length == addresses.length) {
                            if( typeof callback == 'function' ) {
                                callback(coords);
                            }
                        }
                    }
                    else {
                        throw('No results found: ' + status);
                    }
                });
            }
       }
    }

And use this function as:

var address_array = ["514 Broadway, Brooklyn, New York, NY, United States"]
address_func([select_val], function(results){
for(marker in results)
{
   var marker_lat_lng = new google.maps.LatLng(results[marker].lat(), results[marker].lng());
   var marker = new google.maps.Marker({
					 position: marker_lat_lng,
					 map: map,
					});
}
});