Skip to content

Instantly share code, notes, and snippets.

View ajitbohra's full-sized avatar
🎯
Scaling Operations @lubusIN

Ajit Bohra ajitbohra

🎯
Scaling Operations @lubusIN
View GitHub Profile
@ajitbohra
ajitbohra / jQuery string & number concatenation.js
Last active August 29, 2015 14:21
jQuery: String & number concatenation returning NaN
//Scenario 1: String & Math calculation
"height :" + $(document).height() - $(window).height();
//Result: NaN
//Scenario 2: String & Math calculation with parentheses
"height :" + ($(document).height() - $(window).height());
//Result: Height : 1870
//Scenario 3: String without match calculation
"Height:" + $(document).height();
@ajitbohra
ajitbohra / functions.php
Created June 4, 2015 10:24
WooCommerce Removing payment gateway based on country
<?php
// Reomve unsupported payment gateway
function payment_gateway_disable_for_country( $available_gateways ) {
global $woocommerce;
if ( isset( $available_gateways['instamojo'] ) && $woocommerce->customer->get_country() != 'IN' ) {
unset( $available_gateways['instamojo'] );
}
return $available_gateways;
}
@ajitbohra
ajitbohra / functions.php
Created August 20, 2015 17:45
Remove Theme Editor from Appreances
<?php
/*
* Remove theme editor from backend
*/
function remove_editor_menu() {
remove_action('admin_menu', '_add_themes_utility_last', 101);
}
add_action('_admin_menu', 'remove_editor_menu', 1);
?>
@ajitbohra
ajitbohra / functions.php
Last active January 28, 2016 09:20
Removing wootheme update nag
<?php
/**
* Remove the WooThemes Helper plugin nag on admin screen
*/
add_action( 'init', 'lubus_remove_woo_nag' );
function lubus_remove_woo_nag() {
remove_action( 'admin_notices', 'woothemes_updater_notice' );
}
@ajitbohra
ajitbohra / functions.php
Created April 1, 2016 13:31
Wordpress update nag
<?php
add_action('admin_menu','wphidenag');
function wphidenag() {
remove_action( 'admin_notices', 'update_nag', 3 );
}
?>
@ajitbohra
ajitbohra / script.js
Created May 3, 2016 09:46
Force PDF Download
/**
* Forces all PDF links to download automatically, if the browser supports it.
* Otherwise, open the link in a new browser window or tab.
*/
jQuery(document).ready(function($) {
$('a[href$=".pdf"]')
.attr('download', '')
.attr('target', '_blank');
});
@ajitbohra
ajitbohra / functions.php
Created November 16, 2016 12:23
Wordpress Get Plugin Status
<?php
/**
* Check the status of a plugin.
*
* @param string $location Base plugin path from plugins directory.
* @return int 1 if active; 2 if inactive; 0 if not installed
*/
function get_plugin_status($location = '') {
if(is_plugin_active($location)) {
@ajitbohra
ajitbohra / functions.php
Created November 16, 2016 12:26
Wordpress generate plugin install URL
<?php
/**
* http://stackoverflow.com/questions/5327920/how-to-generate-a-wordpress-plugin-install-link
**/
$action = 'install-plugin';
$slug = 'akismet';
wp_nonce_url(
add_query_arg(
@ajitbohra
ajitbohra / functions.php
Last active November 17, 2016 11:40
Wordpress Generate Plugin Activation Link
<?php
/*
* Generate a Link to Activate a Plugin in WordPress
*/
$path = 'woocommerce/woocommerce.php';
$link = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$path), 'activate-plugin_'.$path);
?>
@ajitbohra
ajitbohra / .htaccess
Created February 5, 2017 15:43
Browser Caching For Static Resources
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default expiration: 1 hour after request
ExpiresDefault "now plus 1 hour"
# CSS and JS expiration: 1 week after request
ExpiresByType text/css "now plus 1 week"
ExpiresByType application/javascript "now plus 1 week"
ExpiresByType application/x-javascript "now plus 1 week"
# Image files expiration: 1 month after request