Skip to content

Instantly share code, notes, and snippets.

@nerrad
nerrad / README.md
Created April 23, 2021 15:31
Modifying existing payment method config in WooCommerce Blocks checkout flow

DISCLAIMER: PLEASE READ

Note, this is just a proof of concept as an example of how this type of functionality could be implemented and should be used only if you understand the code. This uses an experimental interface provided by the WooCommerce Blocks API and it may get removed or changed in the future.

This is use at your own risk. Is not an official solution and not supported.

Ideally this kind of behaviour should be something that is provided by the official payment method extension.

WHAT THIS DOES

@nerrad
nerrad / evaluate-php-load-time.md
Created July 19, 2019 20:11
Evaluating WordPress load time via command line

The commands on this page are useful for measuring php response times etc for your WordPress installation via commandline. This gives useful info to help debug issues at the php level separate from the http routes.

I'm pretty sure I didn't come up with this, but I have shared it in a few different places so just adding it to my personal gist repo for reference.

Create the base script

Create a script (name it whatever you want, something like t.php should suffice) in the root directory of your wp install (i.e. the same directory as the wp-config.php and main index.php file for WP. You can substitue whatever you want in the $_SERVER['REQUEST_URI'] to test different pages if you want.

php
@nerrad
nerrad / README.md
Last active February 13, 2019 16:33
Add admin bar notification when gutenberg plugin is active

Installation

Drop this file in your wp-content/mu-plugin folder if you want to fire and forget or just into your wp-content/plugins folder if you want to be able to activate.

Purpose

Now that WordPress 5.0+ has the new block editor merged in, the Gutenberg plugin is for development of features that are not in WordPress core. Since I contribute to the plugin among other projects I do I find that sometimes I forget whether or not the GB plugin is active or not. So I created this handy snippet that inserts a GB is Active indicator in the WordPress admin bar menu when the plugin is active.

@nerrad
nerrad / categorycptrewrite.php
Created October 28, 2012 17:52
Have category archive pages display only posts in a certain custom post type
/**
* This could be extrapolated and used for tags or any other taxonomy really.
*/
add_action('init', 'category_cpt_rewrites');
function category_cpt_rewrites() {
$custom_post_types = array('video', 'audio', 'photo', 'file'); //some example post types
foreach ( $custom_post_types as $post_type ) {
$rule = '^' . $post_type . '/category/(.+?)/?$';
@nerrad
nerrad / rse-fix-wpmandrill
Last active March 1, 2016 03:45
Fix Mandrill plugin
<?php if ( ! defined('ABSPATH')) exit('No direct script access allowed');
/*
Plugin Name: Fix wpMandrill.
Plugin URI: https://gist.github.com/nerrad/2686a4be42da2ca76047
Description: wpMandrill doesn't setup formatted to field addresses to work correctly with the mandrill api. This fixes that.
Version: 1.0.0
Author: Darren Ethier
Author URI: http://roughtsmootheng.in
License: GPLv2
@nerrad
nerrad / css_resources.md
Created January 27, 2014 20:58 — forked from jookyboi/css_resources.md
CSS libraries and guides to bring some order to the chaos.

Libraries

  • 960 Grid System - An effort to streamline web development workflow by providing commonly used dimensions, based on a width of 960 pixels. There are two variants: 12 and 16 columns, which can be used separately or in tandem.
  • Compass - Open source CSS Authoring Framework.
  • Bootstrap - Sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development.
  • Font Awesome - The iconic font designed for Bootstrap.
  • Zurb Foundation - Framework for writing responsive web sites.
  • SASS - CSS extension language which allows variables, mixins and rules nesting.
  • Skeleton - Boilerplate for responsive, mobile-friendly development.

Guides

@nerrad
nerrad / javascript_resources.md
Created January 27, 2014 20:58 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage
@nerrad
nerrad / 0_reuse_code.js
Created January 27, 2014 20:58
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
// Must be in an external file or loaded at the end of wp_footer()
jQuery(document).ajaxSend(function(e, x, a) {
var awesome = 1;
a.data += '&' + jQuery.param( {is_awesome: awesome} );
});
@nerrad
nerrad / show_browser_message.php
Last active December 14, 2015 12:09
#Detect browser message (WP based sites) This is a function I created for Event Espresso to detect older versions of browsers being used to view the site and displaying a message when out of date (according to our requirements). It uses the `wp_check_browser_version()` function WordPress makes available. I've also added some things to not includ…
<?php
/**
* This function just checks the incoming browser and will display a message if it's out of date. We save transients for the user-agents so we don't need to ping the WordPress api on every request.
*
* @return string html formatted message for user
*/
function show_browser_message() {
//let's include the file that will has the wp function we need.
require_once( ABSPATH . 'wp-admin/includes/dashboard.php' );