Skip to content

Instantly share code, notes, and snippets.

@ara303
ara303 / wc-subscription-reminders.php
Created November 14, 2024 06:13
wc-subscription-reminders
// This is imperfect for my needs but it functions as a proof of concept (I guess)...
//
//
// Register the recurring events
function schedule_subscription_reminders($subscription_id) {
$subscription = wcs_get_subscription($subscription_id);
$next_payment_date = $subscription->get_date('next_payment');
if ($next_payment_date) {
@ara303
ara303 / close-match-json.py
Created October 15, 2024 02:22
Accept a main and sub JSON and establish if they have elements in common to merge into one
import json
from difflib import get_close_matches
import os
os.system("color")
class clrs:
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
@ara303
ara303 / wp-only-default-image-sizes.php
Created October 12, 2024 06:17
WordPress remove all but default image sizes
function only_default_image_sizes(){
foreach( get_intermediate_image_sizes() as $size ){
if( ! in_array( $size, ['thumbnail', 'medium', 'medium_large', 'large'] ) ){
remove_image_size( $size );
}
}
}
add_action( 'init', 'only_default_image_sizes' );
@ara303
ara303 / wp-tags-for-category-cpt-with-caching.php
Created September 13, 2024 16:52
Get a list of all of the tags used on a custom post type of a certain category
<?php
/*
* Assumes your custom post type is called `sma_members`, and that your category has ID `70`.
* You'd want to chage this if you reused these.
*/
function get_cached_sma_members_tags() {
$cached_tags = get_transient('sma_members_category_70_tags');
if (false !== $cached_tags) {
@ara303
ara303 / wp-db-table-import-export.php
Created September 10, 2024 17:53
WordPress database table import/export (as CSV)
<?php
/**
* Plugin Name: Table Import/Export
* Description: For internal use only. To access, WP-Admin > Tools > Table Import/Export.
*/
function table_import_export_menu(){
add_submenu_page(
'tools.php',
'Table Import/Export',
'Table Import/Export',
@ara303
ara303 / is_subscriber.php
Last active October 16, 2024 03:19
WooCommerce Subscriptions check if the logged-in user has any or given subscription tiers
<?php
/**
* Check for one or many WooCommerce Subscriptions by SKU
*
* @param string|array $sku_list Optional. Single SKU as string or array of SKUs to check against.
* @return bool True if the user has an active subscription (matching the SKU(s) if provided), false otherwise
*/
function is_subscriber( $sku_list = null ){
$user_id = get_current_user_id();
@ara303
ara303 / dont-use.md
Last active September 30, 2024 23:14
I asked ChatGPT to make a WP customer/admin email editor plugin; it didn't go that well but this may form a decent basis for like a spec of code I actually make myself!

Here is a basic outline of how you can create a WordPress plugin to achieve this:

Plugin Name: Email Template Editor

Plugin Description: A GUI editor for editing email templates with WYSIWYG editors and text replacements.

Plugin Files:

  • email-template-editor.php (main plugin file)
  • email-template-editor-admin.php (admin interface file)
@ara303
ara303 / remove-wp-site-health-default-theme-check.php
Last active April 27, 2021 21:09
Remove the "you need a default theme" WP Site Health check, because it's unnecessary and annoying if you run one default theme that you *do* actively maintain
function YOURPREFIX_remove_default_theme_site_health( $tests ) {
unset( $tests['direct']['theme_version'] );
return $tests;
}
add_filter( 'site_status_tests', 'YOURPREFIX_remove_default_theme_site_health' );
@ara303
ara303 / tumblr-grid-theme-masonry.txt
Created December 3, 2018 18:18
tumblr-grid-theme-masnry.txt
<html lang="en">
<head>
<title>{block:TagPage}#{Tag} | {/block:TagPage}{Title}</title>
<meta type="description" content="{MetaDescription}">
<link rel="shortcut icon" href="{Favicon}">
<link rel="alternate" href="{RSS}">
<meta charset="utf-8">
<style>
body {
margin: 0;
@ara303
ara303 / tumblr-lightbox-for-photos-2018.html
Last active November 30, 2018 15:03
Use Tumblr's built-in lightbox for displaying high-resolution images in a lightbox, basically "free" by leveraging code already in Tumblr. Updated for 2018: no longer requires jQuery, gets `low_res` attribute from image `src`, use more modern JS standards than when this was originally written in 2014!
<script>
let clbPhotos = document.querySelectorAll('.page-index .photo-image[data-highres]'); // Replace this with the selector for whatever you want to be the trigger.
Array.prototype.forEach.call(clbPhotos, function(clbElement, i){
clbElement.addEventListener('click', function(){
let clbAttrs = clbElement.dataset;
let clbData = [{
"width": clbAttrs.highresWidth,
"height": clbAttrs.highresHeight,
"low_res": clbElement.src, // My trigger is the image element so I can take the existing src that is currently being displayed. This is quite good for performance because I know that version is already loaded in. If you make the trigger anything else, you'll need to find another way to provide the low resolution version, it's not optional.
"high_res": clbAttrs.highres