Skip to content

Instantly share code, notes, and snippets.

@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 September 8, 2024 02:57
WooCommerce Subscriptions check if the logged-in user has any or given subscription tiers
/**
* To use, initialise this in your theme's functions.php or a plugin file. Then, in a theme file:
*
* if( is_subscriber() ){
* echo "You subscribe to any product.";
* } else if( is_subscriber( 'subscription_sku' ){
* echo "You subscribe to the `subscription_sku` product.";
* } else {
* echo "No subscriptions found.";
* }
@ara303
ara303 / gpt.md
Last active September 6, 2024 02:12
Probably broken email editor for WordPress

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 / order-confirmation-email.php
Last active September 6, 2024 01:26
Super simple WooCommerce ticket system (may or may not work)
<?php
/**
* this is wrong. needs to be custom. isn't. idk. will fix later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
do_action( 'woocommerce_email_header', $email_heading, $email );
@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
@ara303
ara303 / woocommerce_change_no_shipping_error.php
Created May 17, 2018 15:46
Change the "No shipping available" error message in WooCommerce
function wbsuk_change_no_shipping_error() {
return '<div class="no-shipping-text">Your order cannot be completed automatically. Please <a href="contact">contact us</a> and we will confirm a price to ship to you.</div>';
}
add_filter( 'woocommerce_cart_no_shipping_available_html', 'wbsuk_change_no_shipping_error' );
add_filter( 'woocommerce_no_shipping_available_html', 'wbsuk_change_no_shipping_error' );
@ara303
ara303 / tumblr-theme-required.html
Created November 26, 2015 15:38
Tumblr theme required HTML in order to be considered valid for submission. If you're failing the validation, check to make sure all these custom tags are in your theme file.
<html> <!-- There's no need to set a doctype, Tumblr automatically injects one. -->
<head>
<meta charset="utf-8">
<meta name="description" content="{MetaDescription}">
<link rel="alternate" href="{RSS}">
<link rel="icon" href="{Favicon}">
<style>
{CustomCSS}
</style>
</head>