Skip to content

Instantly share code, notes, and snippets.

View haveigonemental's full-sized avatar

Benjamin Daniel haveigonemental

View GitHub Profile
@jesperorb
jesperorb / php_form_submit.md
Last active April 30, 2024 22:27
PHP form submitting with fetch + async/await

PHP Form submitting

If we have the following structure in our application:

  • 📁 application_folder_name
    • 📄 index.php
    • 📄 handle_form.php
    • 📄 main.js

And we fill our index.php with the following content just to get a basic website with a form working. You should be able to run this through a php-server of your choice.

@Martin-Pitt
Martin-Pitt / pan-zoom-touch-and-trackpad.js
Last active July 1, 2024 00:36
Panning and Pinch-Zoom gesture handler for both touchscreens and trackpads; Works really well on a MacBook trackpad
// Target state
var tx = 0;
var ty = 0;
var scale = 1;
function visualiseTargetState() {
box.style.transform = `translate(${tx}px, ${ty}px) scale(${scale})`;
}
@dasbairagya
dasbairagya / functions.md
Last active January 30, 2024 21:53
Get variation product data on selecting variation options - WooCommerce

Get variation product data on selecting variation options - WooCommerce

functions.php

add_action( 'woocommerce_before_single_variation',
 'action_wc_before_single_variation' );
function action_wc_before_single_variation() {
    ?>
    <script type="text/javascript">
    (function($){
        $('form.variations_form').on('show_variation', function(event, data){
@blizzardengle
blizzardengle / function.php
Last active January 11, 2024 07:56
Allows you to enqueue scripts as modules or import maps in WordPress using the built-in wp_enqueue_script function. You should add this code somewhere in your plugin or theme, most likely your functions.php file.
<?php
// If your PHP version is < 8
if ( ! function_exists( 'str_contains' ) ) {
/**
* Based on original work from the PHP Laravel framework.
*
* @author scm6079
* @link https://www.php.net/manual/en/function.str-contains.php#125977 Original Source
*
@lukecav
lukecav / Queries
Created June 30, 2023 20:52
Delete Action Scheduler actions with a status of failed and canceled and truncate the Action Scheduler logs database table
DELETE FROMwp_actionscheduler_actions WHERE status IN ('failed','canceled')
TRUNCATE wp_actionscheduler_logs