Skip to content

Instantly share code, notes, and snippets.

View jeremysimmons's full-sized avatar

Jeremy Simmons jeremysimmons

View GitHub Profile
<?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';
}
@jeremysimmons
jeremysimmons / wc_get_first_parent.php
Created August 28, 2023 14:55
Get the first parent id of a simple product woocommerce
function wc_get_first_parent($prod_id) {
$group_args = array(
'post_type' => 'product',
'meta_query' => array(
array(
'key' => '_children',
'value' => 'i:' . $prod_id . ';',
'compare' => 'LIKE',
)
),
@jeremysimmons
jeremysimmons / IndexedEnumerable.cs
Created October 18, 2022 14:33
Enumerable With Metadata
public static class IndexedEnumerable
{
public static IndexedEnumerable<T> AsIndexedEnumerable<T>(this IEnumerable<T> source)
{
return Create(source);
}
public static IndexedEnumerable<T> Create<T>(IEnumerable<T> source)
{
return new IndexedEnumerable<T>(source);
@jeremysimmons
jeremysimmons / .bashrc
Created September 19, 2022 16:21
dotnet format with desktop notify script
fcs() {
OUTPUT=$(dotnet format)
if [ $? -eq 0 ]; then
powershell -file $HOME/Toast.ps1 "Dotnet Format", "Completed successfully"
else
powershell -file $HOME/Toast.ps1 "Dotnet Format", "Failed $OUTPUT"
fi
}
@jeremysimmons
jeremysimmons / .gitconfig
Last active June 21, 2023 15:24
gitconfig
[user]
email = jsimmons@jeremysimmons.net
name = jeremy simmons
[alias]
# Get the current branch name (not so useful in itself, but used in other aliases)
branch-name = "!git rev-parse --abbrev-ref HEAD"
# Push the current branch to the remote "origin", and set it to track the upstream branch
publish = "!git push -u origin $(git branch-name)"
# Delete the remote version of the current branch
@jeremysimmons
jeremysimmons / MultipartFormDataContentExample.cs
Created August 23, 2022 00:57
HttpClient MultipartFormDataContent
HttpClient httpClient = new HttpClient();
MultipartFormDataContent form = new MultipartFormDataContent();
form.Add(new StringContent(username), "username");
form.Add(new StringContent(useremail), "email");
form.Add(new StringContent(password), "password");
form.Add(new ByteArrayContent(file_bytes, 0, file_bytes.Length), "profile_pic", "hello1.jpg");
HttpResponseMessage response = await httpClient.PostAsync("PostUrl", form);
response.EnsureSuccessStatusCode();
@jeremysimmons
jeremysimmons / .envrc
Created June 7, 2022 13:10
direnv githooks
git config --local core.hooksPath $PWD/.githooks