Skip to content

Instantly share code, notes, and snippets.

View beneverard's full-sized avatar

Ben Everard beneverard

View GitHub Profile
@Stanton
Stanton / Asset.css
Created November 2, 2012 14:36
LESS noise texture mixin
/**
* Adds a transparent noise texture as a background image to a given element.
* Texture strength can be controlled with @opacity parameter.
*/
.noise (@opacity: .3) {
&:before {
bottom: 0;
content: "";
left: 0;
opacity: @opacity;
@beneverard
beneverard / attachment_rewrite.php
Last active December 29, 2015 08:19
Rewrite attachment URLs from a local version of WordPress to a remote version.
// remove username:password if you don't need htpasswd auth
add_filter('wp_get_attachment_url', function($url) {
$upload_dir = wp_upload_dir();
$file_path = str_replace(site_url() . '/wp-content/uploads', $upload_dir['basedir'], $url);
// check to see if the file exists locally first
if ( file_exists($file_path) ) {
return $url;
@Vheissu
Vheissu / functions.php
Created October 22, 2012 02:36
Bundling the Advanced Custom Fields plugin into a theme using the TGM Plugin Class
add_action( 'tgmpa_register', 'register_required_plugins' );
// This function is called from the above hook
function register_required_plugins()
{
// The plugins array allows us to define multiple plugins we want to include.
// The commented out example shows how we can include and activation a bundled
// plugin zip file in our theme.
$plugins = array(
/* array(
@rolandinsh
rolandinsh / gist:4548975
Created January 16, 2013 17:26
WooCommerce: Add a product to cart programmatically via JS or PHP
<!--
source: http://wordpress.stackexchange.com/a/53516/7577
-->
<a id="buy" href="#">Buy this!</a>
<script>
$('#buy').click(function(e) {
e.preventDefault();
addToCart(19);
return false;
});
@ryanb
ryanb / README.md
Created May 15, 2011 16:24 — forked from copiousfreetime/my-gh-issues.rb
My Github Issues

First install the required gems:

gem install octokit awesomeprint rainbow

Then run it to extract all of your open GitHub issues into files (with comments).

ruby my-gh-issues.rb
@8lane
8lane / functions.php
Created March 31, 2014 10:46
Limit number of cross sells items on cart page in WooCommerce
add_filter('woocommerce_cross_sells_total', 'cartCrossSellTotal');
function cartCrossSellTotal($total) {
$total = '3';
return $total;
}
@x-Code-x
x-Code-x / readme_install_node
Created April 30, 2012 20:52
Install npm node.js on Debian Squeeze / Wheezy / Linux Mint Debian Edition
#Quick cp from http://sekati.com/etc/install-nodejs-on-debian-squeeze
#
#Needed to install TileMill from MapBox
#
#Installs node.js which has npm bundled
#
#Build Dependencies
sudo apt-get update && apt-get install git-core curl build-essential openssl libssl-dev
@tomjn
tomjn / gist:6140909
Last active February 21, 2020 06:35
If you're thinking of using WP_Query, try using this iterator instead, cleaner boilerplate, auto-cleans up after itself
<?php
$pages = new query_loop( array(
'post_type' => 'page'
));
foreach( $pages as $id => $post ) {
the_title();
// etc...
}
@dillinghamio
dillinghamio / Spark User Team Seeding.md
Last active November 23, 2020 13:07
Spark User Team Seeding

Seeding Users & Teams In Laravel Spark

Makes 5 users each with 1 team that has 5 members

Add a team factory to database/factories/ModelFactory.php

$factory->define(App\Team::class, function (Faker\Generator $faker) {
    return [
 'name' =&gt; $faker-&gt;sentence,
@petenelson
petenelson / multiformat-wp-api-response.php
Last active February 26, 2021 21:49
WordPress: Example of returning non-JSON results from the WP-API
<?php
// reference https://github.com/WP-API/WP-API/blob/develop/lib/infrastructure/class-wp-rest-server.php
// serve_request() function
add_filter( 'rest_pre_serve_request', 'multiformat_rest_pre_serve_request', 10, 4 );
function multiformat_rest_pre_serve_request( $served, $result, $request, $server ) {
// assumes 'format' was passed into the intial API route
// example: https://baconipsum.com/wp-json/baconipsum/test-response?format=text