Skip to content

Instantly share code, notes, and snippets.

View mhazgui's full-sized avatar

Montassar Billeh Hazgui mhazgui

View GitHub Profile
@mhazgui
mhazgui / gist:bf186732c30497d9462da93bc42e01a1
Created April 22, 2020 20:01
Cloudflare js worker allow list of countries and block the rest
addEventListener('fetch', event => {
event.respondWith(blockCountries(event.request))
})
//Add countries to this Set to Allow them
const countries = new Set([
"US", // United States
"SG", // Singapore
"BR" // Brazil
])
@mhazgui
mhazgui / val.php
Created October 7, 2020 20:42
Elementor form validation
// Validate password form
add_action('elementor_pro/forms/validation', function ( $record, $ajax_handler ) {
//make sure its our form
$form_name = $record->get_form_settings( 'form_name' );
// Replace MY_FORM_NAME with the name you gave your form
if ( 'Sign-up' !== $form_name ) {
return;
}
@mhazgui
mhazgui / check-webp-support
Created January 9, 2021 22:17
Check if hosting supprt WebP images
<?php
echo "<pre>\n";
print_r( gd_info() );
echo "</pre>\n\n";
?>
//Show only lowest prices in WooCommerce variable products
add_filter( 'woocommerce_variable_sale_price_html', 'wpglorify_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wpglorify_variation_price_format', 10, 2 );
function wpglorify_variation_price_format( $price, $product ) {
// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
$price = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
@mhazgui
mhazgui / gist:6ba8ffc857c6063a4129e180da9ed2bd
Created May 29, 2021 19:30
Safely Remove The Checkout Fields
/* WooCommerce: The Code Below Removes Checkout Fields */
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
unset($fields['billing']['billing_first_name']);
unset($fields['billing']['billing_last_name']);
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_postcode']);
RewriteEngine On
## no-www -> www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE,QSA]
## http -> https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE,QSA]
@mhazgui
mhazgui / remove_checkout_fields.php
Created August 17, 2021 20:22
Remove fields from WooCommerce checkout page.
<?php
add_filter( 'woocommerce_checkout_fields' , 'custom_remove_woo_checkout_fields' );
function custom_remove_woo_checkout_fields( $fields ) {
// remove billing fields
unset($fields['billing']['billing_first_name']);
unset($fields['billing']['billing_last_name']);
unset($fields['billing']['billing_company']);
@mhazgui
mhazgui / .htaccess
Created March 25, 2022 16:16
Force your site to load securely with an .htaccess file
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Header always set Content-Security-Policy "upgrade-insecure-requests;"
# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
@mhazgui
mhazgui / Site Access Log
Created September 14, 2022 19:33
Site Access Log
3.97 - - [14/Sep/2022:19:22:05 +0000] "GET /page/2/?s=Daylong+&post_type=product HTTP/2" 200 42385 "https://www.maparatunisie.tn/?s=Daylong+&post_type=product" "Mozilla/5.0 (Linux; Android 12; CPH2113) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Mobile Safari/537.36"
"197.19.253.97 - - [14/Sep/2022:19:22:09 +0000] "GET /wp-content/uploads/2021/02/daylong-after-sun-repair-100ml.webp HTTP/2" 200 12736 "https://www.maparatunisie.tn/page/2/?s=Daylong+&post_type=product" "Mozilla/5.0 (Linux; Android 12; CPH2113) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Mobile Safari/537.36"
"197.19.253.97 - - [14/Sep/2022:19:22:09 +0000] "GET /wp-content/uploads/2022/07/ma-routine-peau-hypersensible.jpg HTTP/2" 200 98498 "https://www.maparatunisie.tn/page/2/?s=Daylong+&post_type=product" "Mozilla/5.0 (Linux; Android 12; CPH2113) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Mobile Safari/537.36"
"207.46.13.85 - - [14/Sep/2022:19:22:08 +0000] "GET /boutique/page/192 HTTP/2" 301 0 "-" "Mozilla/5.
/19 18:51:01 [error] 1270046#1270046: *1308917 upstream timed out (110: Connection timed out) while reading upstream, client: 197.26.111.61, server: maparatunisie.tn, request: "GET / HTTP/2.0", subrequest: "/redis-store", upstream: "redis2://unix:/var/run/redis-page/redis-page.sock:", host: "www.maparatunisie.tn", referrer: "https://www.maparatunisie.tn/categorie-produit/solaire/?campaignid=20704471184&adgroupid=&keyword=&device=m&gad_source=1&gclid=CjwKCAjwl6-3BhBWEiwApN6_koD9rXoazTSBm6f46kInRbo05Qs0C2xkPjgXRf6QFuvzkCO7M7fwfxoCP30QAvD_BwE"
2024/09/19 18:51:01 [error] 1270046#1270046: *1308917 srcache_store subrequest failed: rc=0 status=504 while sending to client, client: 197.26.111.61, server: maparatunisie.tn, request: "GET / HTTP/2.0", subrequest: "/redis-store", upstream: "redis2://unix:/var/run/redis-page/redis-page.sock", host: "www.maparatunisie.tn", referrer: "https://www.maparatunisie.tn/categorie-produit/solaire/?campaignid=20704471184&adgroupid=&keyword=&device=m&gad_source=1&gclid=CjwKCAjwl6-3Bh