Skip to content

Instantly share code, notes, and snippets.

View danimalweb's full-sized avatar

Daniel Hewes danimalweb

  • Creative Dot
  • Vancouver, Canada
View GitHub Profile
@zeshanshani
zeshanshani / php-rewrite-rule-fix-for-same-slug.php
Last active March 6, 2019 17:52
Fix pagination of page with same slug as of CPT's rewrite slug. This function will fix the same slug conflict of CPT and a static page with pagination.
<?php // Don't copy this line...
/**
* This function will Kill 'blogs/editor' rewrite rules
* to fix the broken pagination issue on this page:
* '/blogs/editor/'
*
* This fix was needed because we add rewrite rules for CPT: editor
* And because '/blogs/editor/' is also a static page, the pagination
* on that page e.g., '/blogs/editor/page/4/' was broken.
import Vue from 'vue';
import posts from './components/posts.vue';
window.axios = require('axios');
window.Vue = Vue;
Vue.component('posts', posts);
const app = new Vue({
el: '#app',
@glueckpress
glueckpress / wp_rocket__wp_get_attachment_image__lazyload.php
Last active January 6, 2020 08:18
[WordPress][WP Rocket] [deprecated] Wrapper function: Applies WP Rocket’s LazyLoad to wp_get_attachment_image()
<?php
/**
* Wrapper function: Applies WP Rocket’s LazyLoad to wp_get_attachment_image()
*
* @link https://developer.wordpress.org/reference/functions/wp_get_attachment_image/
* @link https://github.com/wp-media/wp-rocket/blob/v2.10.9/inc/front/lazyload.php#L24-L47
*
* @param int $attachment_id (Required) Image attachment ID.
* @param string|array $size (Optional) Image size. Accepts any
* valid image size, or an array of width
@ahmadawais
ahmadawais / upload-a-file.MD
Created June 18, 2017 11:07 — forked from websupporter/upload-a-file.MD
Upload a file using the WordPress REST API

Upload files

Using the REST API to upload a file to WordPress is quite simple. All you need is to send the file in a POST-Request to the wp/v2/media route.

There are two ways of sending a file. The first method simply sends the file in the body of the request. The following PHP script shows the basic principle:

@duplaja
duplaja / convert-guest-to-logged-in.php
Last active May 22, 2019 02:56
Convert Guest Orders to Logged In
<?php
//Runs on User Registration
add_action( 'user_register', 'wc_map_guest_initial_match_past_orders', 10, 1 );
function wc_map_guestinitial_match_past_orders( $user_id ) {
//Get current users's e-mail from ID
$current_user = get_user_by( 'ID', $user_id );
$email = $current_user->user_email;
@bschwartz757
bschwartz757 / async.js
Last active November 15, 2023 03:23
Async/await function to fetch data from multiple URLs in parallel
/* Client side, works in Chrome 55 and Firefox 52 without transpilation */
//https://blogs.msdn.microsoft.com/typescript/2016/11/08/typescript-2-1-rc-better-inference-async-functions-and-more/
async function fetchURLs() {
try {
// Promise.all() lets us coalesce multiple promises into a single super-promise
var data = await Promise.all([
/* Alternatively store each in an array */
// var [x, y, z] = await Promise.all([
// parse results as json; fetch data response has several reader methods available:
//.arrayBuffer()
@Uwingame
Uwingame / gist:8c4c25a2a883f6f5213e72d29864ade8
Created December 14, 2016 06:40 — forked from karlwestin/gist:3163157
throttling a window.scroll handler for better performance
// underscore's throttle-metod
var throttle = function(func, wait) {
var context, args, timeout, throttling, more, result;
var whenDone = _.debounce(function(){ more = throttling = false; }, wait);
return function() {
context = this; args = arguments;
var later = function() {
timeout = null;
if (more) func.apply(context, args);
@yellow5
yellow5 / refresh_vagrant_jessie64.bash
Created November 3, 2016 14:17
Script to reload a locally managed vagrant base box with a VMware Fusion provider.
#!/bin/bash
# Save the current directory.
pushd ./
# Change to the directory that contains the VM.
cd ~/Documents/Virtual\ Machines.localized/Debian\ Jessie\ 64\ -\ Base.vmwarevm/
# Defragment and shrink the virtual disk.
/Applications/VMware\ Fusion.app/Contents/Library/vmware-vdiskmanager -d Virtual\ Disk.vmdk
@tjbenton
tjbenton / ready.html
Last active September 14, 2021 20:27
document.ready Promise
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="./ready.js"></script>
<script>
document.ready.then(function() {
console.log('READY!');
});
</script>
@amitramani
amitramani / functions.php
Created August 22, 2016 01:05
How to send WooCommerce Checkout Error Messages to Google Analytics as Events
function load_ga_error_script() {
// Load the JS file (jquery is a dependency)
wp_enqueue_script( 'ga-send-error-event', get_stylesheet_directory_uri() . '/js/ga-send-error-event.js', array('jquery' ) );
}
add_action( 'wp_enqueue_scripts', 'load_ga_error_script' );