Skip to content

Instantly share code, notes, and snippets.

@Amitkpr
Amitkpr / google Autocomplete input type address
Created June 28, 2018 09:33
google Autocomplete input type address
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAlMrFJCY6VldvwPWn9zB1q417eTS7gNno&libraries=places"></script>
<script>
function initialize() {
var input = document.getElementById('locationofproperty');
var options = {
types: ['address'],
componentRestrictions: {
country: 'IN'
@Amitkpr
Amitkpr / update user profile programaticaly in wordpress
Created June 28, 2018 05:33
update user profile programaticaly in wordpress
/* update user profile programaticaly in wordpress*/
add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
function save_extra_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) {
return false;
}
update_user_meta( $user_id, 'phone_number', $_POST['phone_number'] );
@Amitkpr
Amitkpr / Update or remove user for multiple roles in wordpress
Last active June 28, 2018 10:54
Update or remove user for multiple roles in wordpress
/* update user for multiple roles */
function update_and_add_user_role($userId,$role){
$required_id = $userId;
$addMemberToGroup = new WP_User($required_id);
$addMemberToGroup->add_role($role);
}
/*to remove use below function*/
remove_role( $role );
@Amitkpr
Amitkpr / menu.php
Created May 12, 2018 11:50
Make wordpress menu with bootstrap navigation
<?php
/*use bootstrap css and js before use this code*/
//This function is responsible for adding "my-parent-item" class to parent menu item's
function add_menu_parent_class( $items ) {
$parents = array();
foreach ( $items as $item ) {
//Check if the item is a parent item
if ( $item->menu_item_parent && $item->menu_item_parent > 0 ) {
$parents[] = $item->menu_item_parent;
}
@Amitkpr
Amitkpr / Upload multiple images
Created October 4, 2017 15:57
Upload multiple images
<form method="post" action="" enctype="multipart/form-data">
<label>Name</label>
<input type="text" placeholder="Name" name="name">
<br>
<br>
<input type="file" multiple name="file[]">
<br>
<br>
<input type="submit" value="submit" name="submit_val">
</form>
@Amitkpr
Amitkpr / Multiple location map function
Created September 9, 2017 09:06
Multiple location map function
/*********function for multiple location on map*************/
function get_map_by_location($mapData){
$mapId = $mapData['mapid'];
$locations = $mapData['location'];
/* $description = $mapData['description'];
$statename = $mapData['statename']; */
$polyLatLong = $mapData['polyLatLong'];
@Amitkpr
Amitkpr / Barchart function in php
Last active September 9, 2017 06:16
Barchart function in php
//location added like value format
$value .= '['.$i.','.$graphResult.']
$NetROIAfterSellFunction = cashAtClose('NetROIAfterSell','barchart','','Year',''); /*Returning value*/
//make array for data and call function for barchart
$NetROIAfterSellResult = array(
'maintitle'=>'Net ROI After Sell (%)',
'class1'=>'NetROIAfterSell',
'toggleid'=>'NetROIAfterSell1',
@Amitkpr
Amitkpr / Replace string from url in Jquery
Created September 8, 2017 09:55
Replace string from url in Jquery
jQuery(document).ready(function(){
var url= jQuery(location).attr('href');
if (window.location.href.indexOf("#wpcf7-f319-p233-o1") > -1) {
urls = url.replace('#wpcf7-f319-p233-o1','');
window.location.replace(urls);
return false;
}
});
@Amitkpr
Amitkpr / without reload page change url
Created August 26, 2017 10:36
without reload page change url
//without reload page change url
function ChangeUrl(page, url) {
if (typeof (history.pushState) != "undefined") {
var obj = { Page: page, Url: url };
history.pushState(obj, obj.Page, obj.Url);
} else {
alert("Browser does not support HTML5.");
}
}
jQuery(function () {
@Amitkpr
Amitkpr / visual backend not working
Created August 26, 2017 10:33
visual backend not working
visual backend not working
=====================================
html2element: function(html) {
var $template, attributes = {},
template = html;
$template = $(template(this.model.toJSON()).trim()), _.each($template.get(0).attributes, function(attr) {
attributes[attr.name] = attr.value
}), this.$el.attr(attributes).html($template.html()), this.setContent(), this.renderContent()
},