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
@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 / 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 / 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 / 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 / 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 {
/**
<?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 / plugin.php
Created January 20, 2015 23:30
Initial pass at a plugin which reduces the extra number of queries triggered by plugins to look for non-existent options in options table. Use this as a starting point for what you are trying to do.
<?php
/**
* Plugin Name: AnattaDesign Site Optimizer
* Plugin URI: http://anattadesign.com/
* Description: This plugin optimizes the site by reducing the extra number of queries triggered by plugins to look for non-existent options in options table
* Version: 0.1
* Author: Anatta Design
* Author URI: http://anattadesign.com/
*/
@ashfame
ashfame / override-wp-cli-command.php
Last active August 29, 2015 14:19
Example of how to override a WP-CLI command
<?php
if ( defined('WP_CLI') && WP_CLI ) {
class Transient_Mod_Command extends Transient_Command {
public function delete_all() {
// new definition of delete-all subcommand
}
}
@ashfame
ashfame / randomize_preferred_nodes_each_node.php
Created May 3, 2015 15:19
Simple algorithm for picking up 3-7 preferred nodes for each node among a pool of nodes, so that its a little uneven (every node has different number of preferred nodes) but overall there is a balance in distribution.
$nodes = array();
for ( $i = 1; $i <= 100; $i++ ) {
$nodes[ $i ] = '';
}
print_r( $nodes );
foreach ( $nodes as $key => &$node ) {
$random_keys_selection = array_rand( $nodes, mt_rand( 3, 7 ) );
var_dump( $random_keys_selection );
@ashfame
ashfame / fix-wordpress-permissions.sh
Created December 15, 2016 09:33 — forked from Adirael/fix-wordpress-permissions.sh
Fix wordpress file permissions
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro <mike [at] conigliaro [dot] org>
#
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=$1 # <-- wordpress root directory