Skip to content

Instantly share code, notes, and snippets.

View luizbills's full-sized avatar

Luiz Bills luizbills

View GitHub Profile
@luizbills
luizbills / code.php
Created September 27, 2023 17:11
Integração de WooCommerce Bundles com Simulador de Frete
<?php
class WC_Shipping_Simulator_Bundles_Integration {
public function __construct () {
add_filter( 'wc_shipping_simulator_product_needs_shipping', [ $this, 'needs_shipping' ], 10, 2 );
add_filter( 'wc_shipping_simulator_package_validate_virtual_product', [ $this, 'validate_virtual_product' ], 10, 2 );
}
/**
@luizbills
luizbills / code.php
Last active September 27, 2023 21:55
Custom design for WordPress login page
<?php
add_action( 'login_head', 'lpb_login_page_custom_design', 99999 );
function lpb_login_page_custom_design () {
?>
<style>
body.login,
#loginform {
background: #fff;
}
@luizbills
luizbills / uuid.js
Last active September 26, 2023 10:35
Generate UUID v4 in JavaScript
function uuid() {
const s4 = () => Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
}
// usage
const id = uuid(); // example: 88c86c16-e5c4-af27-ef3e-ab2045faf976
@luizbills
luizbills / code.php
Created September 19, 2023 16:18
Deletes product images when a WooCommerce product is permanently deleted
<?php
function lpb_purge_product_images ( $id ) {
if ( ! function_exists( 'wc_get_product' ) ) return; // prevent fatal errors
$product = wc_get_product( $id );
if ( ! $product ) return;
$image_id = $product->get_image_id();
if ( $image_id ) {
@luizbills
luizbills / code.js
Created September 5, 2023 22:48
Black & White Bookmark
// Create a bookmark with the following code in the URL field:
javascript:(function(){var e=document.documentElement;!e.style.filter?e.style.filter='grayscale(1)':e.style.filter=''}())
@luizbills
luizbills / guide.md
Last active August 29, 2023 22:35
WordPress Security in OpenLiteSpeed Server

WordPress Security in OpenLiteSpeed Server

All the following rules are created in WebAdmin > Virtual Hosts > {your_vhost} > Context.

Don't forget to restart the webserver.

Disable access to *.zip, *.ini and *.log files

  • Context Type: Static
  • URI: exp:^.*(ini|log|zip)$
@luizbills
luizbills / guide.md
Last active August 29, 2023 19:32
How to setup FTP + TLS in Ubuntu 20.04

How to setup FTP (with TLS) in Ubuntu 20.04

Install

sudo apt update
sudo apt install openssl proftpd proftpd-mod-crypto
sudo systemctl start proftpd
sudo systemctl enable proftpd
@luizbills
luizbills / code.php
Last active July 28, 2023 12:38
Log exceptions or error messages in debug.log and WooCommerce Status page
<?php
/**
* @param \Throwable|string $err
* @param string $prefix
* @return string The error message
*/
function log_critical ( $err, $prefix = '' ) {
if ( is_a( $err, \Throwable::class ) ) {
$error = $err->getMessage();
@luizbills
luizbills / mini-jquery.js
Last active February 16, 2024 12:30
jQuery-inspired DOM manipulation using modern JavaScript
const $ = (selector, root = document) => root.querySelector(selector);
const $$ = (selector, root = document) => root.querySelectorAll(selector);
const on = (el, evt, cb, opts) => el.addEventListener(evt, cb, opts);
const once = (el, evt, cb) => el.addEventListener(evt, cb, { once: true });
const off = (el, evt, cb) => el.removeEventListener(evt, cb);
@luizbills
luizbills / code.php
Last active July 26, 2023 11:10
Button for clear/empty cart in WooCommerce
<?php
add_action( 'woocommerce_cart_coupon', 'lpb_woocommerce_empty_cart_button' );
function lpb_woocommerce_empty_cart_button () {
$cart_url = add_query_arg( 'empty_cart', 'yes', wc_get_cart_url() );
$label = 'Empty cart';
echo '<a href="' . esc_url( $cart_url ) . '" class="button">' . $label . '</a>';
}
add_action( 'wp_loaded', 'lpb_woocommerce_empty_cart_action', 20 );