Skip to content

Instantly share code, notes, and snippets.

View hadamlenz's full-sized avatar

H. Adam Lenz hadamlenz

  • UNC Chapel Hill
  • Durham, NC.
View GitHub Profile
@hadamlenz
hadamlenz / functions.php
Last active October 21, 2015 19:17
to change the title of an endpoint page in Woocommerce
<?php
function change_order_received_title($title,$id=null){
if ( is_wc_endpoint_url( 'order-received' ) ) {
$title = 'WooTang Clan Commin atcha!';
}
return $title;
}
add_filter( 'the_title', 'change_order_received_title', 10, 2 );
//more on all the endpoints here
//http://wordpress.stackexchange.com/questions/193643/how-to-override-the-title-tag-for-woocommerce-endpoints
@hadamlenz
hadamlenz / page-content.php
Last active October 13, 2015 14:30
A page content template that uses wl_content as the preview and page_content as the live view
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php twentyfifteen_post_thumbnail(); ?>
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="entry-content">
<?php //the_content();
@hadamlenz
hadamlenz / section_editor_utility_functions.php
Last active October 21, 2015 17:52
some utility functions for bu-section-editors
<?php
/* takes the user id
returns an array of groups the user belongs to*/
function get_user_section_groups($user_id){
global $wpdb;
$table = $wpdb->prefix.'postmeta';
$groupsQuery = "SELECT * FROM $table where meta_key = '_bu_section_group_users'";
$groupsResults = $wpdb->get_results($groupsQuery,OBJECT);
if($groupsResults){
$memberGroupArray = [];
@hadamlenz
hadamlenz / Native.GoogleSheetDriver.class.php
Last active October 27, 2015 14:41
A class to interact with google sheets from PHP. Requires php-google-spreadsheet-client (https://github.com/asimlqt/php-google-spreadsheet-client) & google-api-php-client (https://github.com/google/google-api-php-client)
<?php
require_once 'google-api-php-client/autoload.php';
require_once 'php-google-spreadsheet-client/src/Google/Spreadsheet/ListEntry.php';
require_once 'php-google-spreadsheet-client/src/Google/Spreadsheet/ListFeed.php';
require_once 'php-google-spreadsheet-client/src/Google/Spreadsheet/Exception.php';
require_once 'php-google-spreadsheet-client/src/Google/Spreadsheet/WorksheetFeed.php';
require_once 'php-google-spreadsheet-client/src/Google/Spreadsheet/Worksheet.php';
require_once 'php-google-spreadsheet-client/src/Google/Spreadsheet/Util.php';
require_once 'php-google-spreadsheet-client/src/Google/Spreadsheet/UnauthorizedException.php';
require_once 'php-google-spreadsheet-client/src/Google/Spreadsheet/SpreadsheetService.php';
//the function
jQuery.fn.paralaxical = function (speed){
var theOffset;
if($(this).hasClass('left-nav-fixed')){
var lastOffset = Number($(this).attr('data-last-offset-top'));
var negativespeed = speed*-1;
var thetop = $(this).position().top;
var thebottom = thetop + $(this).height();
if( $(this).height() + leftNavTopPosition > $(window).height() ){//yes the nav is larger than the page
if($(this).offset().top > lastOffset && thebottom > $(window).height()){//we are scrolling down
@hadamlenz
hadamlenz / eventFeed.json
Last active December 9, 2015 19:28
what the feeds will look like
{
"events":[
{
"name":"Concert - Eliza Ladd and New College Students: Selfie of the Ancients",
"when":"Thu Apr 28 2016 5:00pm to 6:00pm",
"where":"Mildred Sainer Pavilion, 5313 Bay Shore Road, Sarasota, FL 34243",
"description":"New Music New College presents Chicago\u2019s Third Coast Percussion in a program in advance of their April 30 performance featuring a movement from Augusta Read Thomas\u2019s acclaimed Resounding Earth, composed for bells from around the world; Glenn Kotche\u2019s Wild Sound; and works by Owen Clayton Condon, Thierry De Mey, Isaac Schankler, and Third Coast\u2019s own David Skidmore.",
"startTimeStamp":1455411600,
"endTimeStamp":1455418800,
},
<?php
//add this to your theme's function.php
add_action( 'add_meta_boxes', 'register_meta_boxes');
function register_meta_boxes($post_type){
add_meta_box(
'some_id',//identifyer
'Some Title',//title
'render_metabox',//callback
'post',//screen this will be on
<?php
/*
*a wordpress funtion for dumping in a <pre> and dying
*
*param any $thing the thing you want to var_dump
*param bool $die = should we wp_die or just echo
*/
function wp_predump($thing,$die=true){
$output = '<pre>';
ob_start();
<?php
$moreargs = ['one','two']
add_filter('filtername',function($args) use($moreargs){
//do stuff with more args
})
@hadamlenz
hadamlenz / WP_Inline_Diffing.php
Created December 8, 2016 14:18
Class to display inline diff using wordpress's native text diff engine
<?php
class wp_native_inline_diffing{
public function diffcheck($oldValue, $newValue){
if ( ! class_exists( 'WP_Text_Diff_Renderer_inline', false ) )
require( ABSPATH . WPINC . '/wp-diff.php' );
$renderer = new WP_Text_Diff_Renderer_inline();
$old_lines = explode( "\n", $oldValue );
$new_lines = explode( "\n", $newValue );
$text_diff = new Text_Diff( 'auto', array( $old_lines, $new_lines ) );