Skip to content

Instantly share code, notes, and snippets.

View joshuadavidnelson's full-sized avatar

Joshua Nelson joshuadavidnelson

View GitHub Profile
@joshuadavidnelson
joshuadavidnelson / filter-woocommerce-gridlist-button-wrap-end.php
Last active April 23, 2018 03:01
Filter the WooCommerce Grid/List Outputs
<?php
/**
* Filter the Gridlist Button Wrap End tag.
*
* Requires Grid/List plugin version 1.1.0 or greater
*
* @param string $output The output value
*
* @return string $output The filtered output value
*/
@joshuadavidnelson
joshuadavidnelson / filter-woocommerce-myaccount-order-date.php
Created December 13, 2016 04:12
Alter the output of a specific WooCommerce My Account column, in this case replacing the date format used for displaying the order date.
<?php
/**
* Alter the date order output (in this case, the format of the displayed date).
*
* @param object $order
*/
add_action( 'woocommerce_my_account_my_orders_column_order-date', 'alter_order_date_format', 10, 1 );
function alter_order_date_format( $order ) {
echo '<time datetime="' . date( 'Y-m-d', strtotime( $order->order_date ) ) . '" title="' . esc_attr( strtotime( $order->order_date ) ) . '">' . date_i18n( 'm/d/Y', strtotime( $order->order_date ) ) . '</time>';
@joshuadavidnelson
joshuadavidnelson / rename-woocommerce-brands.php
Created December 13, 2016 03:53
Rename WooCommerce "Brands" to "Manufacturers"
<?php
/**
* Rename WooCommerce "Brands" to "Manufacturers"
*
* @param array $args
*
* @return array
*/
add_filter( 'register_taxonomy_product_brand', 'woocomerce_brands_filter', 10, 1 );
function woocomerce_brands_filter( $args ) {
<?php
/**
* Example code taken from: https://pento.net/2014/02/18/dont-let-your-plugin-be-activated-on-incompatible-sites/
*/
// In this example, only allow activation on WordPress 3.7 or higherclass
MyPlugin {
function __construct() {
add_action( 'admin_init', array( $this, 'check_version' ) );
<?php
/**
* Route the notification to multiple users in a bcc field.
*
* @see https://joshuadnelson.com/user-dropdown-list-custom-notification-routing-gravity-forms/#comment-12376
* @see https://www.gravityhelp.com/documentation/article/notification/
*/
// NOTE: This is untested code, please use with caution. Test and improve as necessary.
@joshuadavidnelson
joshuadavidnelson / get-page-id-by-template.php
Created May 29, 2016 06:04
Grab the page id for the first page using a specific template. Ideal for situations with a template intended for a only one page.
<?php
/**
* Get the first page id with the matching template slug.
*
* @author Joshua David Nelson, josh@joshuadnelson.com
*
* @param string $template This is the template slug, like 'template-about-page.php'
*
* @return mixed $page_id Int or false on failure
*/
@joshuadavidnelson
joshuadavidnelson / default-tax-archive-title.php
Last active March 29, 2018 20:46
Use Taxonomy Name for Default Taxonomy Archive Title in Genesis
<?php
/**
* Default Titles for Term Archives
*
* @author Bill Erickson
* @see http://www.billerickson.net/default-category-and-tag-titles
*
* @param string $headline
* @param object $term
* @return string $headline
@joshuadavidnelson
joshuadavidnelson / example-output.html
Last active January 22, 2024 12:42
Using WordPress responsive images for css background-image property, in-line styling
<style>
.header {
background-image: url(http://local.dev/wp-content/uploads/2016/04/image-300x151.png)
}
@media only screen and (min-width: 300px) {.header {
background-image: url(http://local.dev/wp-content/uploads/2016/04/image-768x386.png)
}}
@media only screen and (min-width: 768px) {.header {
background-image: url(http://local.dev/wp-content/uploads/2016/04/image-1024x515.png)
}}
@joshuadavidnelson
joshuadavidnelson / wpexternalapi.php
Created March 12, 2016 17:57 — forked from chrisgoddard/wpexternalapi.php
WordPress External API endpoint class
/*
WpExternalApi class use
$api = WpExternalApi::get('url-slug');
will create endpoint at www.example.com/url-slug/json and www.example.com/url-slug/xml
$api->set_logic(callback);
function callback($input){
@joshuadavidnelson
joshuadavidnelson / gravity-form-cmb2-options.php
Last active August 5, 2018 17:28
A function to return an array of gravity forms for a CMB2 select field.
<?php
/**
* Get an array of gravity forms.
*
* @since 1.0.0
*
* @return void
*/
function jdn_gf_options() {
$form_array = array();