Skip to content

Instantly share code, notes, and snippets.

View leepeterson's full-sized avatar
:octocat:

Lee Peterson leepeterson

:octocat:
View GitHub Profile
@kjbrum
kjbrum / wp_single_year_monthly_archives.php
Last active February 4, 2017 02:00
Display the monthly archive links for a specific year.
<?php
/**
* Display the archive links for a single year.
*
* @param integer $year The year you would like to display the archives for
* @param string $menu_class Class to add to the ul tag
* @return void
*/
function wp_single_year_monthly_archives($year=null, $menu_class=null) {
if($year == null) {
INITIALISATION
==============
load wp-config.php
set up default constants
load wp-content/advanced-cache.php if it exists
load wp-content/db.php if it exists
connect to mysql, select db
load object cache (object-cache.php if it exists, or wp-include/cache.php if not)
load wp-content/sunrise.php if it exists (multisite only)
absint
access_denied_splash
activate_plugin
activate_plugins
add_action
add_blog_option
add_clean_index
add_comment_meta
add_comments_page
add_cssclass
@kjbrum
kjbrum / WordPress Setup Script.md
Last active March 10, 2018 18:31
Easily set up a project with a Bitbucket repository, ServerPilot application, base plugin and theme, as well as run miscellaneous WordPress tasks.

WordPress Setup Script

Easily set up a project with a Bitbucket repository, ServerPilot application, base plugin and theme, as well as run miscellaneous WordPress tasks. Should be used with https://github.com/Mixd/wp-deploy.

Step 1: Setup project

# Enter your project directory
cd your/desired/project/directory
@kjbrum
kjbrum / csv_to_array.php
Last active July 4, 2018 17:04
Create an associative array from a csv file.
<?php
/**
* Create an associative array from a csv file.
*
* @param file $file The csv file that is going to be parsed
* @return array $data An associative array with the csv headings as keys
*/
function csv_to_array( $file ) {
$data = array();
$header = null;
@shawn-crigger
shawn-crigger / add_to_functions.php
Last active February 15, 2019 03:40
Gravity Form Submission to Sharpspring
<?php
// the trick below is replacing the _4 with the ID of the form you want to post to Sharpspring.
// obviously you need to create the same form in Sharpspring to post to.
add_action( 'gform_after_submission_4', 'post_referral_to_sharpspring', 10, 2 );
@hisnipes
hisnipes / GoogleSpreadsheet_SavePDF_EmailAuto.js
Created February 5, 2014 21:10
Google Apps Script: Using custom menu, save Google Spreadsheet as PDF with custom options (landscape/portrait, gridlines) in Google Drive and automatically email PDF as attachment to multiple recipients. Credit: produced in conjunction with Victor W. Yee.
// Create custom menu within Spreadsheet
function onOpen() {
var submenu = [{name:"Save and Email PDF", functionName:"spreadsheetToPDF"}];
SpreadsheetApp.getActiveSpreadsheet().addMenu('Admin Functions', submenu);
}
// Start spreadsheetToPDF function
function spreadsheetToPDF(key) {
// Authentication stuff
@AustinGil
AustinGil / hero-section.php
Last active April 22, 2019 09:27
An example of my "Progressive Lazy Load" technique in WordPress using vanilla Javascript
<?php while (have_posts()) : the_post(); ?>
<?php
// Get the placeholder image and full size image URLs
if ( has_post_thumbnail() ) {
$image_id = get_post_thumbnail_id();
$full_size_image = wp_get_attachment_image_src( $image_id,'full', true);
$full_size_image_url = $full_size_image[0];
$placeholder_image = wp_get_attachment_image_src( $image_id,'thumbnail', true);
@leepeterson
leepeterson / restapi.txt
Created July 17, 2019 04:17 — forked from chrismccoy/restapi.txt
WordPress REST API Resources
Allow ALL cross origin requests to WordPress REST API
https://github.com/Shelob9/rest-all-cors
WordPress theme using Rest API and Vue.js
https://github.com/rtCamp/VueTheme
WordPress Post from Front End using REST API and Vue.js
http://jimfrenette.com/2017/01/post-from-front-end-wp-api-vuejs/
An offline-first SPA using Vue.js, the WordPress REST API and Progressive Web Apps
<?php
/**
* Filters wp_remote_get() to:
* 1. Return a value from the cache when it's available.
* 2. Write a value to the cache when it's been fetched.
*
* Requires the WP_IMPORT_CACHE constant to be set to a writable directory.
*/
if ( defined( 'WP_CLI' ) && WP_CLI ) {