Skip to content

Instantly share code, notes, and snippets.

View verticalgrain's full-sized avatar

Jamie Graham verticalgrain

View GitHub Profile
// Foreach
foreach ( $array as $item ) {
echo $item;
}
// Foreach with multi-dimensional array keys
foreach ( $array as $key => $item) {
echo $key;
echo $item;
}
@verticalgrain
verticalgrain / wp-cli-cheatsheet.txt
Last active August 9, 2017 23:02
WP-Cli cheatsheet
// Search-replace - multisite
wp search-replace --network --url=site.company.com site.company.com site.company.dev --precise
// Import content to multisite
// Look up child site urls
wp site list --field=url
// Import content, skipping attachments to save time
wp import --url="http://site.dev/childsitename/" contentfile.xml --authors=create --skip=attachment
// Flush permalinks and rewrite htaccess
@verticalgrain
verticalgrain / Vagrant-cheatsheet.txt
Last active July 11, 2017 14:42
Vagrant cheatsheet
// SSH into vagrant box
vagrant ssh
// Start vagrant
vagrant up
// Update
vagrant provision
// Start mysql
@verticalgrain
verticalgrain / object-fit-polyfill.js
Created March 28, 2017 18:06
Object fit polyfill
//Fallback for the object-fit CSS property on IE
if ('objectFit' in document.documentElement.style === false) {
document.addEventListener('DOMContentLoaded', function () {
Array.prototype.forEach.call(document.querySelectorAll('.data-object-fit img'), function (image) {
console.log(image.src);
(image.runtimeStyle || image.style).background = 'url("' + image.src + '") 50% 50% / cover no-repeat';
image.src = 'data:image/svg+xml,%3Csvg xmlns=\'http://www.w3.org/2000/svg\' width=\'' + image.width + '\' height=\'' + image.height + '\'%3E%3C/svg%3E';
});
});
}
@verticalgrain
verticalgrain / git-cheatsheet.txt
Last active May 27, 2019 20:48
Git cheatsheet
// Checkout by hash:
git checkout 970327a74bce000242e08b0d6aeaa19ed03add7c
// To get back to normal branch:
git checkout master
// Git log only merges:
git log --merges
// Remove files from the tree
// First add the file name to .gitignore, then
@verticalgrain
verticalgrain / main.js
Created March 13, 2017 17:28
Typical javascript module pattern
var myDog = new Zoo.Dog('Sherlock', 'beagle');
console.log(myDog.bark()); // Sherlock: woof, woof!
var myWolf = new Zoo.Wolf('Werewolf');
console.log(myWolf.bark()); // Werewolf: woooooow!
@verticalgrain
verticalgrain / owl-carousel.js
Created February 24, 2017 19:56
Owl Carousel go to specific slide
@verticalgrain
verticalgrain / timber-cheatsheet
Last active May 24, 2017 17:25
Wordpress Timber cheat sheet
// Including twig files with vars
{% include "button.twig" with { text: "Click me" } %}
// Debug (enable WP debugging)
{{post|print_r}}// deprecated
{{dump(post)}}
// Image URL with custom image size
{{ TimberImage( fieldname ).src('large') }}
@verticalgrain
verticalgrain / javascript-cheatsheet.js
Last active March 31, 2021 15:36
Javascript Cheat Sheet
const myobject = {}
myobject[ key ] = value
// { key: value }
// Add element to array
const myarray = []
myarray.push(value1)
myarray.push(value2)
// [value1,value2]
@verticalgrain
verticalgrain / .htaccess
Last active February 16, 2017 20:41
Fix CORS policy access errors when accessing fonts on a different domain
<FilesMatch ".(eot|ttf|otf|woff)">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
Header add Access-Control-Allow-Origin "your-domain.com"
## To test access-control-allow-headers in terminal:
## curl -I https://some.cdn.otherdomain.net/media/fonts/somefont.ttf