Skip to content

Instantly share code, notes, and snippets.

View ashfame's full-sized avatar
💭
What parts of our society are best governed by code?

Ashish Kumar ashfame

💭
What parts of our society are best governed by code?
View GitHub Profile
<?php
add_action( 'set_transient_my_transient', function( $value, $expiration ) {
$desired_expiration = 600;
if ( $expiration != $desired_expiration ) {
set_transient( 'my_transient', $value, $desired_expiration );
}
});
@ashfame
ashfame / synthesis.php
Created September 3, 2014 16:49
WP CLI commands available on web-synthesis servers
<?php
function synth_clear_mem_check () {
delete_transient( 'synthesis_memory_check' );
}
add_action('update_option_active_plugins', 'synth_clear_mem_check');
// If we're running from WP CLI, add our CLI commands.
if ( defined( 'WP_CLI' ) && WP_CLI ) {
class Synthesis_Ops_Commands extends WP_CLI_Command {
/**
@ashfame
ashfame / facebook-like-thumbnail-force-default-image-everywhere.php
Last active August 29, 2015 14:01
Forcing single thumbnail to be used on Facebook with "Facebook Like Thumbnail" plugin
<?php
/**
* Plugin Name: Facebook Like Thumbnail - Force Default Image everywhere
* Plugin URI: https://gist.github.com/ashfame/62f59587aaa5c8ecb1ce
* Description: Forces the default image to be used as FB Thumbnail for every page
* Author: Ashfame
* Author URI: http://ashfame.com/
*/
@ashfame
ashfame / snippet.php
Created March 19, 2014 20:20
Querying post relationships in reverse direction when using Advanced Custom Fields plugin on WordPress
<?php
$tour_pages = get_posts(
array(
'post_type' => 'tour',
'meta_query' => array(
array(
'key' => 'tour_author_relationship', // name of custom field
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
@ashfame
ashfame / woocommerce-category-images-from-product.php
Last active June 6, 2023 00:46
Use WooCommerce product image as its category image, if category image is missing
<?php
/**
* Plugin Name: WooCommerce Category Images Modification
* Plugin URI: http://blog.ashfame.com/?p=1117
* Description: Use product image as its category image on category archive pages (To override image for product category, upload one for that category and it will override)
* Author: Ashfame
* Version: 0.1.2
* Author URI: http://ashfame.com/
*/
@ashfame
ashfame / after.php
Created March 17, 2014 22:38
Using WooCommerce email design in custom emails
$email = 'ashfame@example.com';
$subject = 'Custom stuff email';
$email_heading = 'Custom Heading';
$email_content = ''; // whatever it is
ob_start();
do_action( 'woocommerce_email_header', $email_heading );
echo $email_content; // or simply have HTML markup outside PHP tags here
@ashfame
ashfame / magento-set-defaults-address.php
Created June 13, 2013 14:40
Programmatically set default billing/shipping address of customers if they are not set in magento
<?php
require_once ("app/Mage.php");
umask(0);
Mage::app("default");
$collection = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*');
foreach ($collection as $customer) {
@ashfame
ashfame / ios-test.css
Created December 9, 2012 19:38 — forked from tonywok/ios-test.css
iOS Media Queries
// iOS Media Queries
// Goal: capture styles for iPhone, iPhone 3G, iPhone 3GS, iPhone 4, iPhone 4S, iPad, and iPad 2
//
// Author: Tony Schneider (@tonywok)
// Please tell me where I fail. :)
// iPhone v(4,4S) portrait
// test: black text (overwritten by v* portrait) with blue background
@media all and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait) {
a {
@ashfame
ashfame / .gitignore
Created December 5, 2012 10:42
Magento repo sample .gitignore
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@ashfame
ashfame / driver.js
Created August 7, 2012 22:05
kissmetrics-property-device
(function(){
var isFirstVisit = false;
if ( document.referrer == '' ) {
isFirstVisit = true;
} else {
// If referrer is not the site itself
if ( ! ( document.referrer.match( window.location.host ) ) )
isFirstVisit = true;
}
if ( isFirstVisit ) {