Skip to content

Instantly share code, notes, and snippets.

View crstauf's full-sized avatar
🤔
const THINKING = true;

Caleb Stauffer crstauf

🤔
const THINKING = true;
View GitHub Profile
@crstauf
crstauf / wordpress-postmeta-count-by-posttypes.sql
Last active January 10, 2017 22:44
SQL query to count total number of post meta rows per post type
SELECT
p.`post_type`,
COUNT( pm.`post_id` ) as postmeta_count
FROM `wp_posts` as p
JOIN `wp_postmeta` as pm
ON (p.`ID` = pm.`post_id`)
GROUP BY p.`post_type`
ORDER BY
postmeta_count DESC,
p.`post_type` ASC
.screen-reader-text {
clip: rect(1px, 1px, 1px, 1px);
clip-path: polygon(0px 0px, 0px 0px,0px 0px, 0px 0px);
position: absolute !important;
white-space: nowrap;
height: 1px;
width: 1px;
overflow: hidden;
}
@crstauf
crstauf / search-postmeta-fields.php
Created January 28, 2017 02:39
filter function to add postmeta field '_sections' to search
function posts_clauses( $clauses, $wp_query ) {
/* reference: https://adambalee.com/search-wordpress-by-custom-fields-without-a-plugin/ */
if ( !$wp_query->is_search() )
return $clauses;
global $wpdb;
$clauses['join'] .=
' LEFT JOIN ' . $wpdb->postmeta .
@crstauf
crstauf / change-indicator.php
Last active September 22, 2018 04:03
WordPress mu-plugin that adds admin bar integration to indicate whether dev/staging site is clean or dirty. https://cloudup.com/cip1BZXH8kC
<?php
/**
* Functionality to mark a dev install as dirtied (compared to production).
*
* @link https://gist.github.com/crstauf/70c983893cf88ed51d887cec4672e3af GitHub.
*/
if ( !defined( 'ABSPATH' ) || !function_exists( 'add_filter' ) ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
add_action( 'woocommerce_webhook_delivery', function( $args, $response, $duration, $arg, $webhook_id ) {
$order = wc_get_order( $arg );
if (
empty( $order )
|| is_wp_error( $order )
|| !is_a( $order, 'WC_Order' )
)
return;
@crstauf
crstauf / is-dev-env.php
Last active October 22, 2023 03:50
MU-plugin to prevent production functionality on development sites.
<?php
/**
* Plugin Name: Development Environment Preventions
* Description: MU-plugin to prevent production functionality on development sites.
* Plugin URI: https://gist.github.com/crstauf/793d8d70dd6d2572e698f8b46ab6316b
* Author: Caleb Stauffer
* Author URI: https://develop.calebstauffer.com
*/
$production_site_url = '{PRODUCTION SITE URL}';
<?php
/**
* Description: MU-Plugin of CLI command to purge WooCommerce data.
* Plugin URI: https://gist.github.com/crstauf/0917df51455efa1a61058c050565fe72
* Author: Caleb Stauffer
* Author URI: https://develop.calebstauffer.com
*/
if ( !defined( 'WP_CLI' ) || !WP_CLI )
return;
@crstauf
crstauf / wp-expired-transient-timeouts.sql
Created June 13, 2018 05:36
SQL query to select expired WordPress transient timeouts
SELECT `option_name`, `option_value` FROM `wp_options` WHERE `option_name` LIKE '\_transient\_timeout\_%' AND CAST(`option_value` AS UNSIGNED) < UNIX_TIMESTAMP() ORDER BY `option_value`;
@crstauf
crstauf / iOS-Shortcut-HubStaff.md
Last active October 1, 2018 06:39
iOS shortcut to get your HubStaff hours via HubStaff API. #iOS #iOSshortcut

iOS Shortcut: Get HubStaff Hours

  1. Login to your HubStaff account.
  2. Go to https://developer.hubstaff.com/my_apps.
  3. Create an app.
  4. Save the app ID.
  5. Follow the directions for obtaining your auth token.
  6. Save the auth token.
  7. Install the shortcut: https://www.icloud.com/shortcuts/a0489014fbda493bb933b07d7a31bfb3.
  8. Edit the shortcut, adding your App-Token and Auth-Token in the indicated Text boxes.
@crstauf
crstauf / iOS-Shortcut-Harvest.md
Last active October 1, 2018 06:38
iOS shortcut to get your Harvest hours via Harvest API. #iOS #iOSshortcut