Skip to content

Instantly share code, notes, and snippets.

name: project
recipe: wordpress
config:
php: 7.4
webroot: .
<?php
/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the installation.
* You don't have to use the web site, you can copy this file to "wp-config.php"
* and fill in the values.
*
* This file contains the following configurations:
*
# https://github.com/uBlockOrigin/uAssets/pull/3517
twitch-videoad.js application/javascript
(function() {
if ( /(^|\.)twitch\.tv$/.test(document.location.hostname) === false ) { return; }
var realFetch = window.fetch;
window.fetch = function(input, init) {
if ( arguments.length >= 2 && typeof input === 'string' && input.includes('/access_token') ) {
var url = new URL(arguments[0]);
url.searchParams.forEach(function(value, key) {
url.searchParams.delete(key);
// This is a script to help win https://carntech.com/jackie.html
// Note: Level 3 and 7 don't work correctly...so guess those correctly and the remaining levels work correctly
setTimeout( function() {
var pieces = document.getElementsByClassName('piece');
var notJackieUrls = [
'kelsey',
'guy',
'poe',
'will',
'ben',
// Tribe injects a lot of their JavaScript files into the DOM regardless of them being used or not. Here are some handles to remove them.
wp_dequeue_script( 'tribe-events-pro-geoloc' );
wp_dequeue_script( 'tribe-events-list' );
wp_dequeue_script( 'tribe-events-pro' ); // relies on tribe-events-calendar-script
wp_dequeue_script( 'tribe-events-calendar-script' ); // relies on placeholder, resize, datepicker
wp_dequeue_script( 'tribe-events-bar' ); // relies on placeholder, resize, datepicker
wp_dequeue_script( 'tribe-events-bootstrap-datepicker' );
wp_dequeue_script( 'tribe-placeholder' );
wp_dequeue_script( 'tribe-events-jquery-resize' );
<?php
namespace App\CustomRESTRoutes;
/**
* Add a custom route for Tribe Events because...Events are special.
* We can just extend the existing post controller and make changes to it
* to support Tribe Events. THere's no reason to create an entirely new route,
* we just override the constructor and get_items method to suit our needs.
@nitishn
nitishn / dayOfYear.js
Last active August 21, 2016 20:48
I needed to find the current day of the year in javascript. Here's a snippet which helps you do that.
// Taken from http://www.devcurry.com/2011/08/javascript-find-day-of-year.html
var timeStamp = new Date().setFullYear(new Date().getFullYear(), 0, 1);
var yearFirstDay = Math.floor(timeStamp / 86400000);
var today = Math.ceil((new Date().getTime()) / 86400000);
var dayOfYear = today - yearFirstDay;
// If you want hours, you can just multiply by 24.
// I subtracted by 24 because I wanted the beginning of the day, not the end!
var hoursOfYear = dayOfYear * 24 - 24
/**
* Grab the upcoming events from the Events Manager plugin. However, we need to make sure only the first
* instance of a recurring event shows up. So, we need to essentially get reccuring/non-recurring events
* and then merge the result set. This is not supported by the plugin currently...
* @return array
*/
function getUpcomingEvents()
{
$upcomingEvents = array();
$recurring = array();
@nitishn
nitishn / dates.php
Created May 19, 2016 17:16
Working with dates in WordPress
// Working with dates is annoying. Time is annoying, especially with timezones involved.
// In WP, you have to worry about the timezone set by WordPress AND the timezone set in php.ini.
// A safe bet when working with date logic in WP, is to assume that the timezone set by the WP backend is correct.
// More than likely, an event is local and thus should use WP timezone.
// HOWEVER, when working with php's DateTime class, you need to manually set the timezone or you'll have
// inconsistant dates! Below is a snippet which helps set the timezone, does calculations, and then sets it back.
// Set to WP timezone
$phpTimezone = date_default_timezone_get();
@nitishn
nitishn / xml-to-csv.php
Created February 9, 2015 21:47
Read an XML file and write out a CSV file in php.
<?php
// How to open an XML file and write out it's contents as a CSV!
// Using sample XML file here https://msdn.microsoft.com/en-us/library/ms762271(d=printer,v=vs.85).aspx
$filexml='books.xml';
if (file_exists($filexml)) {
$xml = simplexml_load_file($filexml);
$f = fopen('books.csv', 'w');
foreach($xml->book as $book) {
$values = array(
'author' => $book->author,