Skip to content

Instantly share code, notes, and snippets.

View haveigonemental's full-sized avatar

Benjamin Daniel haveigonemental

View GitHub Profile
@JoonHoSon
JoonHoSon / iframe.js
Created October 29, 2024 06:55 — forked from PechenkiUA/iframe.js
Youtube iframe contentWindow.postMessage command
document.querySelector('iframe').contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
@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
@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
*
@PechenkiUA
PechenkiUA / iframe.js
Created December 29, 2022 07:18
Youtube iframe contentWindow.postMessage command
document.querySelector('iframe').contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
@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){
@Martin-Pitt
Martin-Pitt / pan-zoom-touch-and-trackpad.js
Last active January 14, 2025 13:04
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})`;
}
@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.

@rahilwazir
rahilwazir / handle_upload.md
Last active January 4, 2025 00:26
Change upload directory, async upload, handle upload in WordPress

Change upload directory

// Grabbed from edd plugin
function set_upload_dir() {

	// Override the year / month being based on the post publication date, if year/month organization is enabled
	if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
		// Generate the yearly and monthly dirs
 $time = current_time( 'mysql' );