Skip to content

Instantly share code, notes, and snippets.

View jeremysimmons's full-sized avatar

Jeremy Simmons jeremysimmons

View GitHub Profile
@jeremysimmons
jeremysimmons / multiple-row-upsert.php
Created May 29, 2025 13:35
multiple row upsert in wordpress
global $wpdb;
// your table (with a UNIQUE or PRIMARY KEY on the upsert column(s))
$table = $wpdb->prefix . 'my_table';
// prepare your data as an array of rows
$data = [
[ 'id' => 1, 'col_a' => 'foo', 'col_b' => 'bar' ],
[ 'id' => 2, 'col_a' => 'baz', 'col_b' => 'qux' ],
[ 'id' => 3, 'col_a' => 'lorem','col_b' => 'ipsum' ],
@jeremysimmons
jeremysimmons / functions.php
Created May 22, 2025 21:16
extend woocommerce cart session cookie
add_filter('woocommerce_cookie_expiration', 'extend_woocommerce_cart_cookie_expiration');
function extend_woocommerce_cart_cookie_expiration($expiration) {
return 60 * 60 * 24 * 14; // 14 days in seconds
}
add_filter('auth_cookie_expiration', function($expire, $user_id, $remember) {
return 60 * 60 * 24 * 14; // 14 days
}, 10, 3);
@jeremysimmons
jeremysimmons / git_commands.md
Last active May 15, 2025 21:30
Git Commands
@jeremysimmons
jeremysimmons / .git_config
Created May 9, 2025 22:36
I don't want to see me coworkers work.
# .git/config - local repo config
# limit to only files you want to see. your branches begin with your git username by convention
[remote "origin"]
fetch = +refs/heads/main:refs/remotes/origin/main
fetch = +refs/heads/jeremysimmons/*:refs/remotes/origin/jeremysimmons/*
@jeremysimmons
jeremysimmons / multipart.cs
Last active June 20, 2024 17:44 — forked from erkantaylan/multipart.cs
c# download multi part
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
namespace TestApp
{
internal class Program
{
@jeremysimmons
jeremysimmons / cdtilde.bat
Created May 21, 2024 19:09
cdtilde recipe
@echo off
:: https://stackoverflow.com/a/52688643/26877
set dirname=""
set dirname=%*
set orig_dirname=%*
:: remove quotes - will re-attach later.
set dirname=%dirname:\"=%
set dirname=%dirname:/"=%
<?php
// https://stackoverflow.com/a/22818089/26877
// wp-content/mu-plugins/buffer.php
/**
* Output Buffering
*
* Buffers the entire WP process, capturing the final output for manipulation.
*/
ob_start();
;with product_types (object_id, product_type) as (
select tr.object_id, t.name
from wp_term_relationships tr
join wp_term_taxonomy tax on tr.term_taxonomy_id = tax.term_taxonomy_id and tax.taxonomy = 'product_type'
join wp_terms t on t.term_id = tax.term_id
)
select
p.ID
,p.post_parent
,p.post_status
@jeremysimmons
jeremysimmons / upgrader_process_complete_example.php
Created January 2, 2024 18:33
wordpress upgrader_process_complete example
function my_plugins_update_completed( $upgrader_object, $options ) {
// If an update has taken place and the updated type is plugins and the plugins element exists
if ( $options['action'] == 'update' && $options['type'] == 'plugin' && isset( $options['plugins'] ) ) {
foreach( $options['plugins'] as $plugin ) {
// Check to ensure it's my plugin
if( $plugin == plugin_basename( __FILE__ ) ) {
// do stuff here
}
}
@jeremysimmons
jeremysimmons / admin_head_post_edit_check.php
Created September 18, 2023 20:50 — forked from petenelson/admin_head_post_edit_check.php
WordPress admin action hooks for listing/adding/editing posts or pages
/* actions fired when listing/adding/editing posts or pages */
/* admin_head-(hookname) */
add_action( 'admin_head-post.php', 'admin_head_post_editing' );
add_action( 'admin_head-post-new.php', 'admin_head_post_new' );
add_action( 'admin_head-edit.php', 'admin_head_post_listing' );
function admin_head_post_editing() {
echo 'you are editing a post';
}