Skip to content

Instantly share code, notes, and snippets.

@thomasgriffin
thomasgriffin / database-indexes.txt
Created November 22, 2023 12:30
Helpful indexes and SQL queries to add to make WordPress run faster.
alter table `wp_usermeta` add index `ndx_meta_key_meta_val1` (`meta_key`(40), `meta_value`(191));
alter table `wp_postmeta` add index `ndx_meta_key_meta_val1` (`meta_key`(40), `meta_value`(191));
alter table `wp_termmeta` add index `ndx_meta_key_meta_val1` (`meta_key`(40), `meta_value`(191));
alter table `wp_commentmeta` add index `ndx_meta_key_meta_val1` (`meta_key`(40), `meta_value`(191));
alter table `wp_edd_customermeta` add index `ndx_meta_key_meta_val1` (`meta_key`(40), `meta_value`(191));
alter table `wp_edd_licensemeta` add index `ndx_meta_key_meta_val1` (`meta_key`(40), `meta_value`(191));
alter table `wp_posts` add index `ndx_id_post_status_val1` (`id`, `post_status`);
SELECT 'autoloaded data in KiB' as name, ROUND(SUM(LENGTH(option_value))/ 1024) as value FROM wp_options WHERE autoload='yes'
UNION
@afragen
afragen / gist-oembed.php
Last active August 5, 2022 19:56
WordPress plugin to embed gists or gist files.
<?php
/**
* Gist oEmbed.
*
* @package Fragen\Gist_OEmbed
*
* Plugin Name: Gist oEmbed
* Plugin URI: https://gist.github.com/afragen/36ab01da116aadd27a3f4d85cce90390
* Description: oEmbed Gist or files within Gists.
* Version: 0.6.2
@polevaultweb
polevaultweb / edd_perpetual_discounts.php
Last active June 28, 2022 08:31
EDD - Allow discounts to be set to apply to all renewals
<?php
// Add new Discount setting the to discount add and edit forms
add_action( 'edd_add_discount_form_before_use_once', array( $this, 'edd_perpetual_discounts_setting_add_form' ) );
add_action( 'edd_edit_discount_form_before_use_once', array( $this, 'edd_perpetual_discounts_setting_edit_form' ) );
// Handle saving the settings on form submission
add_filter( 'edd_update_discount', 'edd_perpetual_discounts_add_meta' );
add_filter( 'edd_insert_discount', 'edd_perpetual_discounts_add_meta' );
@webzunft
webzunft / canceled-subscriptions.sql
Last active October 4, 2022 13:15
SQL queries to analyse canceled subscriptions managed with EDD Recurring Payments
# Basic queries to analyse canceled subscriptions using EDD Recurring Payments pre EDD 3.0
# Use EXPLAIN if you have large stores since the "notes" column is not indexed and queries can take some time
# Some of these reports might be worth storing as Views and look at the graphs PHPMyAdmin can also create from them
# List subscription cancelation with creation and cancelation date, as well as the user who canceled
# good as a basis for further queries
SELECT ID,
created,
REGEXP_SUBSTR( REGEXP_SUBSTR( notes, '.* Status changed from active to cancelled .*' ), '^[a-z]+ [0-9]+, [0-9]+' ) AS 'date',
@aymericbeaumet
aymericbeaumet / delete-likes-from-twitter.md
Last active May 3, 2024 11:24
[Recipe] Delete all your likes/favorites from Twitter

Ever wanted to delete all your likes/favorites from Twitter but only found broken/expensive tools? You are in the right place.

  1. Go to: https://twitter.com/{username}/likes
  2. Open the console and run the following JavaScript code:
setInterval(() => {
  for (const d of document.querySelectorAll('div[data-testid="unlike"]')) {
    d.click()
 }
@danielbachhuber
danielbachhuber / postmark-split-wp-mail.php
Created July 30, 2019 22:34
Splits wp_mail() with more than 40 bcc into multiple batches
<?php
/**
* Splits a wp_mail() call with more than 40 bcc
* headers into multiple batches.
*
* Postmark only accepts 50 bcc, so this ensures the API call doesn't fail.
*
* @param array $args Original arguments passed to wp_mail().
* @return
*/
<?php
/*
Plugin Name: Enable/Disable plugins when doing local dev
Plugin URL: https://gist.github.com/pbiron/52bb63042cf220256ece89bc07fb57b0
Description: If the WP_LOCAL_DEV constant is true, enables/disables plugins that you specify
Version: 0.1
License: GPL version 2 or any later version
Author: Paul V. Biron/Sparrow Hawk Computing
Author URI: https://sparrowhawkcomputing.com
*/
@ollietreend
ollietreend / acf-php-to-json.php
Last active April 22, 2024 11:12
Convert Advanced Custom Fields Pro configuration from PHP to JSON.
<?php
/**
* Plugin Name: Convert ACF PHP to JSON
* Description: Convert Advanced Custom Fields Pro configuration from PHP to JSON.
*/
namespace ConvertAcfPhpToJson;
/**
* Add submenu item under 'Custom Fields'
@jchristopher
jchristopher / my.sql
Last active October 24, 2017 00:27
Get EDD Customer email and license key for Customers with ! 'active' Recurring subscriptions
# THIS IS NOT TESTED ENOUGH !!!!!!!!!!!!!!!!!! EXPECT INACCURACIES !!!!!!!!!!!!!!!!!!
# THIS IS CRAZY CRAZY SLOW
# ADJUST THE LIMIT ON LINE 20 ACCORDINGLY (READ: IF YOU DARE)
SELECT *
FROM (
SELECT
SUBSTRING_INDEX(SUBSTRING_INDEX(edd_customers.name, ' ', 1), ' ', -1) as firstname,
edd_customers.email AS email,
pm2.meta_value as license_key
FROM wp_edd_customers AS edd_customers
#!/bin/bash
#
## store the arguments given to the script
read oldrev newrev refname
## Where to store the log information about the updates
LOGFILE=./post-receive.log
# The deployed directory (the running site)
DEPLOYDIR=/directory/to/deploy/to
GITDIR=/directory/above/hooks/repo_name.git