Skip to content

Instantly share code, notes, and snippets.

// change slug on post if title is changed.
add_action( 'save_post', 'icput_post_title_fix' );
function icput_post_title_fix( $post_id ) {
$url = rwmb_get_value( 'canonical_url', '', $post_id );
if ( empty( $url ) ) {
return;
}
@topher1kenobe
topher1kenobe / gist:73053b393cad123510e1bbbecf1b4457
Created October 11, 2022 20:20
take a screenshot, ssh it someplace
#!/bin/bash
/opt/homebrew/bin/ffmpeg -ss 0.5 -f avfoundation -r 30.000030 -i "0" -t 1 /Users/topher/window_shots/"grmi_$(date +%F_%H-%M-%S).jpg" -frames:v 1
unset -v latest
for file in /Users/topher/window_shots/*; do
[[ $file -nt $latest ]] && latest=$file
done
keychain --noask --eval id_dsa
@topher1kenobe
topher1kenobe / podcast_link_buttons.php
Created December 5, 2021 21:11
Podcast Buttons file for wppodcasts.com
@topher1kenobe
topher1kenobe / get_remote_auth_token.php
Last active August 31, 2020 19:13
Class method that gets an authenitcation token from BigCommerce
/*
* Get the auth token from BigCommerce
*
* @access public
* @return string $token
*/
public function get_remote_auth_token() {
// Set up the REST authentication headers
$headers[ 'X-Auth-Token' ] = $this->access_token;
/*
* Get the auth token from local option
*
* @access public
* @return NULL
*/
public function get_local_auth_token() {
// get the token from the options table
$this->auth_token = get_option( 'bigcommerce_auth_token' );
$meta_query = [
'meta_key' => 'pmp_required_levels',
'meta_value' => get_pmpro_subscription_ids( get_current_user_id() ),
'meta_compare' => 'IN',
'post_type' => 'li_resources',
];
// value holds an array like this
Array
(
@topher1kenobe
topher1kenobe / gist:8511994
Created January 19, 2014 22:42
Make WordPress image insert function use html5 figures
/**
* Swap Default TinyMCE Tags for Figure Tags on Images
*/
function html5_insert_image( $html, $id, $caption, $title, $align ) {
$title = esc_attr( $title );
$caption = sanitize_text_field( $caption );
$id = absint( $id );
$url = esc_url( wp_get_attachment_url( $id ) );
@topher1kenobe
topher1kenobe / Conditional SQL
Created September 1, 2013 11:54
Conditional SQL in MySQL
SELECT
SUM(
CASE
WHEN `home_school_id`= 42 THEN `away_score`
WHEN `away_school_id`= 42 THEN `home_score`
END
) as points_against
FROM
`games`
WHERE
@topher1kenobe
topher1kenobe / gist:5430861
Last active December 16, 2015 11:58
Delete WordPress transient under the proper conditions
// delete featured coaches transient on coach save
function delete_featured_transient($post_id) {
// First we want to make sure that this is a real save, not simply an auto save
if ( !wp_is_post_revision( $post_id ) ) {
// now we declare our custom content type, because we only want to run this
// on the save of this type
$slug = 'coaches';