Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@topher1kenobe
topher1kenobe / pacc_cross_post.php
Created June 30, 2014 12:50
Example of cross posting from a WordPress subsite to the parent site
<?php
/*
Plugin Name: PACC Cross Post
Plugin URI: http://thepacc.com
Description: Allows subsites to cross post to the main site
Author: Topher
Version: 1.0
Author URI: http://codeventure.net
*/
function bg_video_scripts() {
wp_enqueue_script( 'bg-backgrounds', get_stylesheet_directory_uri() . '/assets/jquery.videoBG.js', array( 'jquery' ) );
wp_enqueue_script( 'bg-backgrounds-actuator', get_stylesheet_directory_uri() . '/assets/script.js', array( 'jquery' ) );
}
add_action( 'wp_enqueue_scripts', 'bg_video_scripts' );
### Keybase proof
I hereby claim:
* I am topher1kenobe on github.
* I am topher1kenobe (https://keybase.io/topher1kenobe) on keybase.
* I have a public key whose fingerprint is B667 2067 B47F D1B8 AC08 7340 8314 A0AF 19F8 B110
To claim this, I am signing this object:
@topher1kenobe
topher1kenobe / include-parent-css.php
Last active August 29, 2015 14:05
Include parent theme CSS properly
function t1k_get_parent_theme_css() {
wp_enqueue_style( 'make-theme', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 't1k_get_parent_theme_css' );
@topher1kenobe
topher1kenobe / checkout_cart.php
Created March 14, 2015 21:24
Easy Digital Downloads adjusted checkout template file
<?php
/**
* This template is used to display the Checkout page when items are in the cart
*/
global $post; ?>
<table id="edd_checkout_cart" <?php if ( ! edd_is_ajax_disabled() ) { echo 'class="ajaxed"'; } ?>>
<thead>
<tr class="edd_cart_header_row">
<?php do_action( 'edd_checkout_table_header_first' ); ?>
@topher1kenobe
topher1kenobe / gist:5430835
Last active December 16, 2015 11:58
Store WordPress query in a transient
// Let's create the function to be used as a shortcode
function featured_coaches($atts) {
// My content type is for Motor Coaches, and we want to get the ones that have
// the Featured box checked, but not the Sold box.
// I'm starting out saying we want 3, and no sold
extract(shortcode_atts(array(
'num' => 3
,'sold' => false
@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';
@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: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 ) );
$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
(