Clearing the cache in Drupal

Please find below to clrear cache in Drupal.

1. The easiest way to clear the Drupal cache is to go to Administration > Configuration > Development > Performance
(http://example.com/admin/config/development/performance)
2. Click the button “Clear all caches”

The most convenient way to rebuild Drupal’s cache is by using Drush.

Drupal 8:
drush cache-rebuild

Drupal 7 and earlier:
drush cache-clear all

Advertisement

Send attachment through gravity form mail in WordPress

Please find below code to send any documnet, PDF send through mail

/* Gravity forms */
function wdm_add_attachment( $notification, $form, $entry ) {
$upload_dir = wp_upload_dir();
if($form_id==9){
$notification[“attachments”] = $upload_dir[‘basedir’].’/pdf/order_new.pdf’;
}
return $notification;
}

add_filter(“gform_notification”, “wdm_add_attachment”, 9, 3);

Generate random string in PHP

/*Random String*/
function generateRandomString($length = 2) {
$characters = ‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’;
$charactersLength = strlen($characters);
$randomString = ”;
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength – 1)];
}
return $randomString;
}
/*Random String*/

PHP MySQL connect, insert, select data from advanced version…

<?php
$dbHost = ‘localhost’;
$dbUsername = ‘root’;
$dbPassword = ”;
$dbName = ‘db_name’;
//Connect with the database
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);

if ($db->connect_errno) {
printf(“Connect failed: %s\n”, $db->connect_error);
exit();
}
/*Get data from table*/
$accounts = $db->query(“SELECT * FROM table_name”);

while($row = $accounts->fetch_assoc()){
echo $row[‘sub_id’];
}

/*Store data in table*/

$query = “INSERT INTO table_name VALUES (‘$str’)”;
$sql = $db->query($query);
?>

WordPress core functionality features

/* Disable the Admin Bar. */
add_filter( ‘show_admin_bar’, ‘__return_false’ );
remove_action( ‘personal_options’, ‘_admin_bar_preferences’ );

// stop wp notice to update core
add_filter( ‘pre_site_transient_update_core’, create_function( ‘$a’, “return null;” ) );

// stop wp notice to update plugins
remove_action( ‘load-update-core.php’, ‘wp_update_plugins’ );
add_filter( ‘pre_site_transient_update_plugins’, create_function( ‘$a’, “return null;” ) );

Add increment & decrement for product quantity based on ajax success

/*16-06-16 start*/
jQuery(document).ready(function(){
jQuery(document).ajaxSuccess(function() {
jQuery( ‘.wc-new div.quantity:not(.buttons_added), wc-new td.quantity:not(.buttons_added)’ ).addClass(                               ‘buttons_added’ ).append( ‘<input type=”button” value=”+” class=”plus” />’ ).prepend( ‘<input                                        type=”button” value=”-” class=”minus” />’ );
});
});
/*16-06-16 end*/

window.location in javascript

Please find below code…

//Get current page url
var curr_url = window.location.href

//Get hostname
var host_name = window.location.hostname

//Display the path name of the current URL
var path_name = window.location.pathname

//Get protocol of URL return http:// or https://
var proto = window.location.protocol;

//Get parameters from URL
var x = location.search;
Result:
?email=someone@example.com

Get woocommerce cart items

Get woocommerce cart items

foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values[‘data’];
$cart_products[] = $_product->id;
}

WC()->cart->add_to_cart( $product_id );   // Add product to cart

WC()->cart->remove_cart_item( $cart_item_key );   // Remove product from cart