Skip to content

Instantly share code, notes, and snippets.

@karpstrucking
karpstrucking / wpse74896.php
Last active January 18, 2016 17:43
Exclude WC categories from widget that only contain out of stock products Raw
<?php
// Inspired by this WPSE question: http://wordpress.stackexchange.com/questions/74896/woocommerce-product-category-widget-hide-categories-that-have-no-products-in-s
add_filter( 'woocommerce_product_categories_widget_args', 'wpse_74896' );
function wpse_74896( $args ) {
global $wpdb;
if ( ! empty( $args['current_category'] ) ) {
$current = $args['current_category'];
$current_clause = "( term_id = '{$current}' OR parent = '{$current}' ) AND ";
@karpstrucking
karpstrucking / gist:aff3118f67344df8d0b0
Created January 6, 2016 20:27
WooCommerce - Filter orders based on how the order was created (admin versus natural)
<?php
/*
Plugin Name: WooCommerce Filter by "Created Via"
Description: Filter orders based on how the order was created
Author: GoWP
Author URI: https://www.gowp.com
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
@karpstrucking
karpstrucking / gist:83f217e9a4c7e5100695
Last active September 4, 2015 15:48
Force disabling of the expanded editor option in WordPress
add_action( 'init', 'gowp_disable_editor_expand_setting' );
function gowp_disable_editor_expand_setting() {
global $_updated_user_settings;
$_updated_user_settings['editor_expand'] = 'off';
}
add_action( 'admin_footer', 'gowp_disable_editor_expand_field' );
function gowp_disable_editor_expand_field() {
$screen = get_current_screen();
if ( 'post' == $screen->base ) : ?>
@karpstrucking
karpstrucking / iwp_uptime.sh
Created August 25, 2015 17:02
Example of a simple uptime checking script using sites in InfiniteWP database
#!/bin/bash
# Database configuration
DBNAME=""
DBUSER=""
DBPASS=""
# Email configuration
@karpstrucking
karpstrucking / gist:a89cb6e9c50af18fa4df
Last active August 29, 2015 14:23
Delay the reveal of the WooCommerce - Gravity Forms Product Add-Ons form until clicked
/*
* Delays the display of the associated Gravity Form until the visitor has clicked an "Add to cart"-style button
* Requires WooCommerce and WooCommerce - Gravity Forms Product Add-Ons plugins
*/
add_action( 'wp_footer', 'gowp_woocommerce_gravityforms_reveal_delay' );
function gowp_woocommerce_gravityforms_reveal_delay() {
if ( class_exists( 'WooCommerce' ) && class_exists( 'woocommerce_gravityforms' ) && is_product() ) {
?>
<script type="text/javascript">
@karpstrucking
karpstrucking / gist:a0803d7a8900a5e10be9
Created May 2, 2015 14:08
Add ability to apply one WC product variation price to all variations of the same product
<?php
add_action( 'woocommerce_product_data_panels', 'gowp_global_variation_price' );
function gowp_global_variation_price() {
?>
<script type="text/javascript">
jQuery( document ).ready( function() {
a = jQuery( '<a href="#">Apply to all Variations</a>' );
b = jQuery( 'input[name^="variable_regular_price"]' );
a.click( function( c ) {
@karpstrucking
karpstrucking / gist:ec8e7de6b6f570f38ab8
Created April 25, 2015 10:21
Copy parent theme's mods to child theme on activation
<?php
add_action( 'after_switch_theme', 'gowp_copy_theme_mods' );
function gowp_copy_theme_mods() {
$mods = get_theme_mods();
if ( is_null( $mods ) || ( ( 1 == count( $mods ) ) && ! $mods[0] ) ) {
$parent = wp_get_theme()->get('Template');
$child = basename( dirname( __FILE__ ) );
update_option( "theme_mods_$child", get_option( "theme_mods_$parent" ) );
}
@karpstrucking
karpstrucking / gist:09d1e93668c69153941c
Created April 18, 2015 23:57
batch WP update script
#!/bin/bash
# This script will apply outstanding core/plugin updates for all WP installations on the server
# Each site will be tested after updates and, if offline as a result, the updates will be reverted
# The script assumes a folder structure of: /home/username/domain.com/html/
# WP-CLI (http://wp-cli.org/) and git (http://git-scm.com/) are required
find /home/*/*/html -maxdepth 1 -type d -name wp-content | while read FindPath
do
<?php
// remove theme-provided shortcode
remove_shortcode( 'recent_works' );
// add our own modified version
add_shortcode( 'recent_works', 'my_shortcode_recent_works' );
function my_shortcode_recent_work( $atts, $content = null ) {
... // your modified shortcode function here
<?php
private function outputImage($filepath){
$info = UniteFunctionsRev::getPathInfo($filepath);
$ext = $info["extension"];
$filetime = filemtime($filepath);
$ext = strtolower($ext);
if($ext == "jpg")