Skip to content

Instantly share code, notes, and snippets.

View Garconis's full-sized avatar
🐞
Debugging

Jon Fuller Garconis

🐞
Debugging
View GitHub Profile
@Garconis
Garconis / woocommerce-small-image-thumbnail-cropping.php
Created August 2, 2019 13:42
WooCommerce | Thumbnail upscale & correct crop in WordPress
<?php
/* Upscale images that are otherwise too small for thumbnail cropping */
function gc_thumbnail_upscale( $default, $orig_w, $orig_h, $new_w, $new_h, $crop ){
if ( !$crop ) return null; // let the WordPress default function handle this
$aspect_ratio = $orig_w / $orig_h;
$size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
$crop_w = round($new_w / $size_ratio);
@Garconis
Garconis / woocommerce-shipping-class-in-shopping-cart.php
Created July 31, 2019 20:19
WooCommerce | Display the shipping class of items in the cart, and change shipping methods (and verbiage) based on the shipping classes in the cart
<?php
/**
* Hide a Flat Rate option (instance #7) when the "Call for Quote" shipping class is in the cart
* from: https://www.bolderelements.net/support/knowledgebase/hide-shipping-method-when-cart-contains-shipping-class/
*/
function fs_hide_shipping_when_class_is_in_cart( $rates, $package ) {
// shipping class IDs (slugs) that need the method removed
$shipping_classes = array('call-for-quote');
$if_exists = false;
@Garconis
Garconis / shortcode-loop-of-cpt-with-acf-fields.php
Created July 16, 2019 20:58
WordPress | Shortcode Loop of CPT with ACF Fields (Bing Devils score cards) [work-in-progress]
<?php
// create shortcode to list all Games in Page
add_shortcode( 'fs-game-schedule-page-loop', 'fs_sc_game_schedule_page_loop' );
function fs_sc_game_schedule_page_loop( $atts ) {
ob_start();
// define attributes and their defaults
extract( shortcode_atts( array (
'post_type' => 'fs_schedule',
@Garconis
Garconis / cpt-remove-slug-hack.php
Last active July 3, 2019 16:50
WordPress | Hack to get CPT to have no post-type slug
<?php
/**
* NOTE, this causes PAGES AND POSTS TO NOT WORK!
*/
/**
* NOTE, this also requires your post type (e.g., via CPT UI) to have a Rewrite to True,
* and a Custom Rewrite Slug of / (forward slash) ... which probably isn't best practice.
* Sources:
@Garconis
Garconis / impreza-theme-options-per-cpt.php
Created June 12, 2019 15:16
Impreza | Help update theme meta data to certain post types (only run once)
<?php
$local_args = array(
'posts_per_page' => -1,
'post_type' => 'fs_local',
);
$local_posts_array = get_posts( $local_args );
foreach ( $local_posts_array as $post ) {
update_post_meta( $post->ID, 'us_header_id', '__defaults__' );
update_post_meta( $post->ID, 'us_titlebar_id', '__defaults__' );
@Garconis
Garconis / project-go-back-link-based-on-category.php
Created May 28, 2019 15:20
WordPress | Create a "Go Back" link based on what category the Project belongs to
@Garconis
Garconis / divi-custom-preloader-function.php
Created May 24, 2019 18:45
Divi | Custom Preloader PHP function
<?php
add_action('wp_footer', 'fs_preloader_code');
function fs_preloader_code(){
if(is_front_page()) { ?>
<div class="fs-preloader">
<div class="fs-status"></div>
</div>
<?php }
};
add_action('wp_head', 'fs_preloader_js');
@Garconis
Garconis / acf-repeater-field-shortcode.php
Created May 17, 2019 17:42
WordPress | ACF Repeater Field output with shortcode
<?php
// ACF Group Shortcode
function shortcode_acf_find_my_flowers( $atts ) {
// begin output buffering
ob_start();
if( have_rows('where_to_find_my_flowers') ) {
@Garconis
Garconis / tag-cloud-based-on-category-via-shortcode.php
Created May 6, 2019 15:07
WordPress | Tag cloud for categories via shortcode
<?php
function tag_cloud_shortcode($atts) {
// first make sure we are within a category
if (is_category()) {
// get info of current category
$category = get_category( get_query_var( 'cat' ) );
// get current category ID
@Garconis
Garconis / wp-all-export-post-date-time-format.php
Last active April 25, 2019 20:56
WP All Export | Ensure post dates are pulled from actual time and not GMT date
<?php
/** In WP All Export, add a new ID field and give it a custom Column Name, then...
* set the field to "Export the value returned by a PHP function"...
* where the function name is fs_format_get_date ...
* then add this function to the Function Editor, so that...
* the column in the export will use the proper date timezone and post time, rather than the "post_date_gmt" value
*/
function fs_format_get_date ($id) {
$new_date = get_the_date($d = 'Y-m-d H:i:s', $id);
return $new_date;