Skip to content

Instantly share code, notes, and snippets.

View sudarshann's full-sized avatar
💭
Modernizing

Sudarshan Anbazhagan sudarshann

💭
Modernizing
View GitHub Profile
public static function acf_validate_vocher_code_unique($valid, $value, $field, $input_name) {
// Bail early if value is already invalid.
if ($valid !== true) {
return $valid;
}
$result = self::validate_voucher_unqiue($value);
if( !empty($result) ){
return $result;
@sudarshann
sudarshann / validate-acf-field-repeater.php
Last active May 2, 2023 06:52
Custom validation for ACF Repeater Field values
add_filter('acf/validate_value/name=voucher', 'acf_validate_vocher_code_unique', 10, 4);
function acf_validate_vocher_code_unique($valid, $value, $field, $input_name) {
// Bail early if value is already invalid.
if ($valid !== true) {
return $valid;
}
$result = validate_voucher_unqiue($value);
@sudarshann
sudarshann / functions.php
Created May 17, 2020 13:07 — forked from maddisondesigns/functions.php
WooCommerce Custom Fields for Simple & Variable Products
/*
* Add our Custom Fields to simple products
*/
function mytheme_woo_add_custom_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
// Text Field
@sudarshann
sudarshann / pagespeed_optimize_images.sh
Created July 24, 2020 21:25 — forked from julianxhokaxhiu/pagespeed_optimize_images.sh
Recursively optimize all PNG and JPG files wherever they are from the script position and inner ( based on OPTING, PNGCRUSH, ADVANCECOMP and JPEGOPTIM )
#!/bin/bash
# Improved as per feedback from @pascal - https://gist.github.com/julianxhokaxhiu/c0a8e813eabf9d6d9873#gistcomment-3086462
find . -type f -iname "*.png" -exec optipng -nb -nc {} \;
find . -type f -iname "*.png" -exec advpng -z4 {} \;
find . -type f -iname "*.png" -exec pngcrush -rem gAMA -rem alla -rem cHRM -rem iCCP -rem sRGB -rem time -ow {} \;
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -exec jpegoptim -f --strip-all {} \;
@sudarshann
sudarshann / woocommerce-out-of-stock.php
Created August 7, 2020 12:10
Custom woocommerce out of stock message
add_filter( 'woocommerce_product_add_to_cart_text', 'superbotics_add_to_cart_text', 20, 2);
add_filter( 'woocommerce_product_single_add_to_cart_text', 'superbotics_add_to_cart_text', 20, 2);
function superbotics_add_to_cart_text( $text, $_product ) {
if ( ! $_product->is_in_stock() ) {
$text = __('<Custom Text>', 'superbotics-customizations');
}
return $text;
}
@sudarshann
sudarshann / encoding-video.md
Created September 7, 2020 13:07 — forked from glen-cheney/encoding-video.md
Encoding video for the web

Encoding Video

Installing

Install FFmpeg with homebrew. You'll need to install it with a couple flags for webm and the AAC audio codec.

brew install ffmpeg --with-libvpx --with-libvorbis --with-fdk-aac --with-opus
@sudarshann
sudarshann / export-html-table-xls.js
Created September 28, 2020 20:54
Export any standard html tag to xls file with javascript.
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
return function(tableID, name) {
table = document.getElementById(tableID);
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML};
var link = document.createElement("a");
link.download
function copyToClipboard(textToCopy) {
var textArea;
function isOS() {
//can use a better detection logic here
return navigator.userAgent.match(/ipad|iphone/i);
}
function createTextArea(text) {
textArea = document.createElement('textArea');
apt update
apt upgrade
apt install apache2
a2enmod headers rewrite
systemctl restart apache2
sudo ufw allow in "Apache"
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
@sudarshann
sudarshann / .htaccess
Last active December 21, 2020 10:32
Htaccess to block url based injections
<IfModule mod_rewrite.c>
# Block suspicious user agents and requests
RewriteCond %{HTTP_USER_AGENT} (libwww-perl|wget|python|nikto|curl|scan|java|winhttp|clshttp|loader) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} (<|>|'|%0A|%0D|%27|%3C|%3E|%00) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} (;|<|>|'|"|\)|\(|%0A|%0D|%22|%27|%28|%3C|%3E|%00).*(libwww-perl|wget|python|nikto|curl|scan|java|winhttp|HTTrack|clshttp|archiver|loader|email|harvest|extract|grab|miner) [NC,OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=http:// [OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=(\.\.//?)+ [OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=/([a-z0-9_.]//?)+ [NC,OR]
RewriteCond %{QUERY_STRING} \=PHP[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} [NC,OR]