Skip to content

Instantly share code, notes, and snippets.

View tracyfloyd's full-sized avatar

Tracy Floyd tracyfloyd

View GitHub Profile
@tracyfloyd
tracyfloyd / wordpress-taxonomy-query-perfomance-with-OR.php
Last active February 24, 2021 17:18
WordPress - Taxonomy query performance with OR
<?php
/*
* SQL doesn't care that the terms come from different taxonomies, but WP_Query does because they're looked up by slug. So the query it generates is very innefficient.
* These filters will combine the various taxoomy ids into a single array so query can be simplified
*/
$search_args['tax_query'] = array(
'relation' => 'OR',
);
if ( !empty($query_vars['size']) ) {
@tracyfloyd
tracyfloyd / formidable-forms__add-error-message-to-document-title.php
Last active January 29, 2020 14:34
Formidable Forms Plugin - Customize page title if errors present for screen readers
<?php
/**
* Customize form page title if errors present
*/
add_filter('frm_validate_entry', function ( $errors, $values ) {
if ( !empty($errors) ) {
add_filter( 'pre_get_document_title', function( $title ) {
return 'Errors Found - ' . $title;
}, 999, 1 );
}
@tracyfloyd
tracyfloyd / get_product_qty_in_orders.php
Last active September 21, 2019 21:05
WordPress WooCommerce - Get total qty of product in all orders of a given order status (or statuses)
<?php
public function get_product_qty_in_orders( $product_id, $order_status )
{
global $wpdb;
if ( is_string($order_status) ) {
$order_status = array($order_status);
}
if ( !empty($product_id) && !empty($order_status) && is_array($order_status) ) {
@tracyfloyd
tracyfloyd / 20180828.php
Last active August 28, 2018 13:03
Better Font Awesome - Fix for get_icon_array_version_5() error
<?php
private function get_icon_array_version_5() {
$icons_metadata = $this->get_icons_metadata();
$icons = array();
// Add style prefixes.
foreach ( $icons_metadata as $slug => $metadata ) {
if ( !empty($metadata['search']['terms']) ) {
@tracyfloyd
tracyfloyd / gravity-forms-auth-net-additional-transaction-data.php
Last active August 29, 2018 21:21
GravityForms Authorize.net Additional Transaction Data
/**
* Modify the transaction data sent to Authorize.net
* Ref: plugins/gravityformsauthorizenet/authorizenet.php
* Ref: https://legacy.forums.gravityhelp.com/topic/sending-additional-information-to-authorizenet-via-namevalue-pairs
*/
add_action( 'gform_authorizenet_transaction_pre_capture', 'app_gform_authorizenet_transaction_pre_capture', 10, 5 );
function app_gform_authorizenet_transaction_pre_capture( $transaction, $form_data, $config, $form, $entry )
{
if ( $form['id'] == 14 ) {
@tracyfloyd
tracyfloyd / regex-select-html-element-and-contents.js
Created August 15, 2018 13:37
Regex to select html element and contents
(?s)<div class="something".*?<\/div>
@tracyfloyd
tracyfloyd / floodlight-tag-builder.js
Last active August 10, 2018 15:22
Floodlight Tag Builder
var App = {
floodlight: {
createFloodlightTagUrl: function(floodlightOptions){
var tagUrl = 'https://' + floodlightOptions.src + '.fls.doubleclick.net/activityi' +
';src=' + floodlightOptions.src +
';type=' + floodlightOptions.type +
';cat=' + floodlightOptions.cat +
';dc_lat=' + floodlightOptions.dc_lat +
';dc_rdid=' + floodlightOptions.dc_rdid +
@tracyfloyd
tracyfloyd / gravity-forms-add-transaction-id-to-email-notifications.php
Last active June 27, 2018 17:26
Gravity Forms - Add Transaction ID to Email Notifications
<?php
/**
* Process custom app_transaction_id merge tag
* Note: Add the string: {app_transaction_id} in your email notification body
*/
add_filter('gform_replace_merge_tags', 'app_gform_replace_merge_tags__app_transaction_id', 10, 7);
function app_gform_replace_merge_tags__app_transaction_id( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format )
{
$merge_tag = '{app_transaction_id}';
@tracyfloyd
tracyfloyd / us-state-names-abbrevs.php
Created April 10, 2018 15:11 — forked from maxrice/us-state-names-abbrevs.php
US State Names & Abbreviations as PHP Arrays
<?php
/* From https://www.usps.com/send/official-abbreviations.htm */
$us_state_abbrevs_names = array(
'AL'=>'ALABAMA',
'AK'=>'ALASKA',
'AS'=>'AMERICAN SAMOA',
'AZ'=>'ARIZONA',
'AR'=>'ARKANSAS',
@tracyfloyd
tracyfloyd / thin-close.scss
Created October 4, 2017 19:15
Thin X Icon (Pure CSS)
a.close {
color: transparent;
display: block;
height: 32px;
position: fixed;
right: 0;
top: 0;
transition: transform .25s ease-in-out;
width: 32px;