Skip to content

Instantly share code, notes, and snippets.

View alexstandiford's full-sized avatar

Alex Standiford alexstandiford

View GitHub Profile
@alexstandiford
alexstandiford / barebones-walker.php
Last active November 4, 2016 10:16
Basic Nav Menu Walker Structure for custom WordPress themes.
<?php
class myWalker extends Walker_Nav_Menu {
// Displays start of a level. E.g '<ul>'
// @see Walker::start_lvl()
function start_lvl(&$output, $depth=0, $args=[]) {
$output .= '<ul>';
}
// Displays end of a level. E.g '</ul>'
// @see Walker::end_lvl()
function end_lvl(&$output, $depth=0, $args=[]) {
@alexstandiford
alexstandiford / settings.php
Created November 14, 2016 16:24
WordPress Options, Simplified
class option{
public function __construct($ID,$title,$object,$callback = null,$page = null,$section = null,$prefix = 'your_prefix_'){
$this->ID = $prefix.$ID;
$this->title = $title;
$this->callback = ($callback == null) ? array($object,$this->ID.'_callback') : array($object,$callback);
$this->page = ($page == null) ? 'eav-settings-admin' : $page;
$this->section = ($section == null) ? 'eav_options_id' : $section;
}
}
@alexstandiford
alexstandiford / alter-oembed.php
Created December 23, 2016 15:50
Alters oembed querystring parameters
<?php
/**
* Cleans up YouTube Video Embeds
**/
function imp_custom_youtube_querystring( $html, $url, $args ) {
if(strpos($html, 'youtube')!= FALSE) {
$args = [
'rel' => 0,
'controls' => 0,
'showinfo' => 0,
@alexstandiford
alexstandiford / embed.php
Last active January 14, 2017 18:39
oEmbed helper class for WordPress
<?php
/**
* Embed helper class for all WordPress embeds
* User: Alex
* Date: 1/13/2017
* Time: 1:11 PM
*/
namespace embedHelper;
@alexstandiford
alexstandiford / override.php
Created February 10, 2017 15:26
Age Verifier Template Override
<?php //do not include this line when you copy/paste
function eav_override_template(){
$result = '';
//Starts the form
$result = "<div id='taseav-age-verify' class='taseav-age-verify'>";
$result .= "<form class='taseav-verify-form'>";
$result .= "<h2>" . get_option('eav_form_title') . "</h2>";
//If the settings call to enter the age, do this
@alexstandiford
alexstandiford / query.php
Created March 7, 2017 11:24
Basic The Events Calendar Query
<?php
$events = new WP_Query([
'post_type' => 'tribe_events',
'posts_per_page' => 9,
'order' => 'asc',
'orderby' => 'EventStartDate',
]);
?>
@alexstandiford
alexstandiford / mergedQuery.php
Last active June 20, 2017 11:45
Combine two WordPress Queries and append the results to the final query
<?php
/**
* Combines two WP_Queries, and appends the second to the first
* @author: Alex Standiford
* @date : 6/20/2017
*/
class mergedQuery extends \WP_Query{
public $post_ids_to_merge = [];
@alexstandiford
alexstandiford / post-query-shortcode.php
Created June 29, 2017 14:22
Just a simple way to search for things in a WordPress install. Allows for an easy way to search for locations where a shortcode is used
<?php
function tas_search(){
ob_start();
//Searches by string
$args = [
's' => 'yop_poll', //Or whatever
'post_type' => 'any',
'posts_per_page' => -1,
];
@alexstandiford
alexstandiford / override-the-events-calendar-template-location.php
Created November 13, 2018 13:58
Injects a plugin directory into The Events Calendar Template Location checks
<?php
//Inject Events Calendar template controls in this plugin
add_filter('tribe_events_template', function($file, $template){
$override_template = TKGEM_ROOT_DIR.'tribe-events/'.$template;
$theme_template = trailingslashit(get_stylesheet_directory()).'tribe-events/'.$template;
if(file_exists($override_template) && !file_exists($theme_template)){
$file = TKGEM_ROOT_DIR.'tribe-events/single-event.php';
}
return $file;
@alexstandiford
alexstandiford / overflow-helper-bookmarklet.js
Last active December 12, 2018 21:01
Bookmarklet to toggle red border on all elements. Good for figuring out overflow issues.
javascript:(function(){
const outline = document.querySelector('.outline-everything-with-red');
if(!outline){
style = document.createElement('style');
style.classList.add('outline-everything-with-red');
style.appendChild(document.createTextNode('* {outline: 1px solid red;}'));
document.head.appendChild(style);
console.log('The following elements appear to be wider than the document.');