Skip to content

Instantly share code, notes, and snippets.

@digamber89
digamber89 / filtes.php
Last active November 29, 2015 08:01
Show Filters Attached to Hook
<?php
/* Attaching to Init because plugin files and theme files all have been loaded by this point and no output has been generated */
/* using anonymous function */
add_action('init', function(){
/* replace wp_head with any filter or action hook */
$hooks = digthis_see_hooked_actions('wp_head');
var_dump($hooks);
});
function digthis_see_hooked_actions($hook = NULL){
@digamber89
digamber89 / removeSingleton.php
Created November 29, 2015 09:52
Singleton Class Unhook action and Filters
class myClass{
protected static $instance = null;
public function __construct(){
add_filter('the_content', array($this, 'add_text'));
}
public static function get_instance(){
// If the single instance hasn't been set, set it now.
@digamber89
digamber89 / load-admin-scripts.php
Created July 14, 2016 09:09
Correct way to enqueue styles and scripts for your plugin option pages
// Load the scripts conditionally
add_action( 'load-' . $menu_page, array($this, 'enqueue_scripts') );
/* This function is only called when our plugin's page loads! */
public function enqueue_scripts(){
add_action('admin_enqueue_scripts', array($this, 'load_admin_scripts') );
}
/* Load Scripts only if necessary */
public function load_admin_scripts(){
@digamber89
digamber89 / autocomplete-orders.php
Created October 29, 2015 05:44
Autocomplete Orders
/**
* Auto Complete all WooCommerce orders.
*/
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
# Gzip compression
<IfModule mod_deflate.c>
# Active compression
SetOutputFilter DEFLATE
# Force deflate for mangled headers
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
# Don’t compress images and other uncompressible content
@digamber89
digamber89 / change-front-page-template.php
Created March 16, 2017 17:37
Change Front Page Template
add_filter( 'template_include', 'portfolio_page_template', 99 );
function portfolio_page_template( $template ) {
if ( is_front_page() ) {
$new_template = locate_template( array( 'tpl-duplicate-homepage.php' ) );
if ( '' != $new_template ) {
return $new_template ;
}
@digamber89
digamber89 / filter-cpt-by-taxonomy.php
Created June 22, 2017 07:53
Category Page Filtering
<?php
/**
* Display a custom taxonomy dropdown in admin
* @author Mike Hemberger
* @link http://thestizmedia.com/custom-post-type-filter-admin-custom-taxonomy/
*/
add_action('restrict_manage_posts', 'tsm_filter_post_type_by_taxonomy');
function tsm_filter_post_type_by_taxonomy() {
global $typenow;
$post_type = 'team'; // change to your post type
@digamber89
digamber89 / functions.php
Created August 14, 2017 11:18
Allow Shop Manager to view the Preview Code
<?php
add_filter('woo_preview_emails_min_capability', 'wpe5321_set_min_capacity');
function wpe5321_set_min_capacity($capability){
$capability = 'manage_woocommerce';
return $capability;
}
@digamber89
digamber89 / smooth-scroll.js
Created October 23, 2017 10:29
Goto Scroll Smooth Animation
/* requires jquery */
jQuery(function($){
var jump = function(e) {
if(e){
e.preventDefault();
var href = $(this).attr("href");
var hashvalue = '';
if( href.length != 0){
var site_url = href.split('#')[0];
hashvalue = href.substr(href.indexOf("#"));
<?php
/**
* Checkout Form
*
* This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-checkout.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and