Skip to content

Instantly share code, notes, and snippets.

View logichub's full-sized avatar

Kashif Rafique logichub

View GitHub Profile
@kingkool68
kingkool68 / filter.php
Last active September 21, 2017 21:57
Using `wp_debug_backtrace_summary()` to only filter something when called from a particular function or method
/*
Here we're filtering the site_url() and get_site_url() functions which are called dozens and dozens of times during a request.
In this case we only want to modify $url if the filter was called from a particular PHP class (rtCamp\WP\Nginx\Helper)
*/
add_filter( 'site_url', function( $url = '' ) {
$backtrace = wp_debug_backtrace_summary();
if ( stripos( $backtrace, 'rtCamp\WP\Nginx\Helper' ) ) {
$url = str_replace( 'https://', 'http://', $url );
}
return $url;
@panosru
panosru / acf-vc-templatera-integration.php
Last active January 3, 2024 16:47
Dynamic population of ACF fields in VC and Templatera (BETA)
<?php
add_filter( 'the_content', 'remove_fontawesome', 99 );
function remove_fontawesome($content) {
wp_dequeue_style( 'tt-font-awesome' );
wp_dequeue_style('dhvc-woo-font-awesome');
wp_dequeue_style('dhvc-woocommerce-page-awesome');
return $content;
}
@mgibbs189
mgibbs189 / gist:4a8e5c0e018e257eceb1d057477b576f
Last active September 19, 2016 23:46
FacetWP - using the facetwp_indexer_post_facet filter
<?php
function lh_fwp_index_coming_soon_facet( $return, $params ) {
$facet_params = $params['defaults'];
if ( 'cf/edd_coming_soon' == $facet_params['facet_source'] ) {
$value = get_post_meta( $facet_params['post_id'], 'edd_coming_soon', true );
$value = empty( $value ) ? 'Available' : 'Coming Soon';
$facet_params['facet_value'] = $value;
$facet_params['facet_display_value'] = $value;
FWP()->indexer->index_row( $facet_params );
@mgibbs189
mgibbs189 / functions.php
Created September 14, 2016 10:55
FacetWP - customize EDD Coming Soon label
<?php
function fwp_index_coming_soon( $params, $class ) {
if ( 'cf/edd_coming_soon' == $params['facet_source'] ) {
$params['facet_display_value'] = 'Availability';
}
return $params;
}
add_filter( 'facetwp_index_row', 'fwp_index_coming_soon', 10, 2 );
@mathetos
mathetos / functions.php
Last active March 12, 2019 14:10
Function for conditionally enqueing minified or un-minified scripts based on WP_DEBUG
<?php
add_action( 'wp_enqueue_scripts', 'debug_theme_enqueue_styles' );
function debug_theme_enqueue_styles() {
if (WP_DEBUG == true) :
$random = mt_rand();
wp_enqueue_style( 'main-css-unminified', get_template_directory_uri() . '/assets/styles/build/main.css', '', $random );
@unnikked
unnikked / botscheduler.js
Last active July 24, 2021 00:29
Bot scheduler for Telegram - to use with IFTTT - please check https://unnikked.ga/build-telegram-bot-hook-io/ for instructions
module['exports'] = function bot (hook) {
var request = require('request');
var TOKEN = hook.env.bot_scheduler_token;
var ENDPOINT = 'https://api.telegram.org/bot' + TOKEN;
console.log(hook.params);
// generic handler to log api call responses
var handler = function (err, httpResponse, body) {
var response = JSON.stringify({
@mikejolley
mikejolley / gist:3b37b9cc19a774665f31
Last active April 21, 2023 12:44
Example instance based shipping method
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Sample instance based method.
*/
class WC_Shipping_Test_Method extends WC_Shipping_Method {
@christiangenco
christiangenco / download_egghead_videos.md
Last active January 29, 2024 03:16 — forked from ldong/download_egghead_videos.md
download egghead videos
@mgibbs189
mgibbs189 / test.php
Created January 11, 2016 16:08
FacetWP - add a WooCommerce "On Sale" facet
<?php
// Create a facet named "on_sale" with the Data Source of "Post Type"
// Add this to functions.php
function fwp_is_sale( $params, $class ) {
if ( 'is_sale' == $params['facet_name'] ) {
$post_id = (int) $params['post_id'];
$variable_sale_price = get_post_meta( $post_id, '_min_variation_sale_price', true );
$sale_price = get_post_meta( $post_id, '_sale_price', true );
@vishalbasnet23
vishalbasnet23 / Sublime-stuffs.txt
Created November 4, 2015 08:00
Install PHPCS with WordPress Coding Standard with Sublime Text 3
1. cmd+shift+p
2. Type phpcs and install it
3. Preferences > Package Settings > Php Code Sniffer > User settings