Skip to content

Instantly share code, notes, and snippets.

View ericnicolaas's full-sized avatar
🎯
Focusing

Eric Daams ericnicolaas

🎯
Focusing
View GitHub Profile
@ericnicolaas
ericnicolaas / gist:8b9d4a632f124c319b01
Last active August 29, 2015 14:03
Register an image control in the Wordpress Customizer
/**
* Create an image control in the Customizer with an ID of 'logo_url'.
*
* This is added to the 'title_tagline' section.
*/
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'logo_url',
array(
'settings' => 'logo_url',
'section' => 'title_tagline',
'label' => __( 'Logo', 'my_theme' )
@ericnicolaas
ericnicolaas / gist:349c4550c23e90be53b7
Created July 10, 2014 23:09
Option 1: Retina image control in the Wordpress Customizer
/**
* Retina image control.
*
* Essentially, you just create two separate image controls, one of which is for the regular version of the logo,
* the other for the retina version.
*
* This is a simple solution with a few downsides:
*
* 1. It can be confusing for users who may not understand what is required for a retina version.
* 2. There is nothing enforcing the 2x sizing of the retina version.
@ericnicolaas
ericnicolaas / gist:37f8bc4ce87913e0d056
Created July 10, 2014 23:22
Option 2: Retina image control in the Wordpress Customizer
/**
* Retina image control.
*
* This solution involves creating a new control, implemented as the
* Sofa_Customizer_Retina_Image_Control class.
*
* Using this control, we get a regular image control with a simple
* checkbox underneath asking the user whether the image is retina-ready.
* This means that the user can just upload a single image and tick a box
* if it is correctly sized for retina screens (i.e. it's twice the size
@ericnicolaas
ericnicolaas / class-sofa-customizer-retina-image-control.php
Last active August 29, 2015 14:04
Wordpress Customizer Retina Image Control: Sofa_Customizer_Retina_Image_Control class
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'WP_Customize_Control' ) ) return;
if ( ! class_exists( 'Sofa_Customizer_Retina_Image_Control' ) ) :
/**
@ericnicolaas
ericnicolaas / average-apache-process
Last active August 29, 2015 14:04
Print average size of Apache process (Centos 6)
ps aux | grep httpd | grep -v pts | awk '{ tot += $6; procs += 1; print $2,$6,$11 } END { print "TOTAL: ",tot,"/",procs,"=",tot/procs }'
@ericnicolaas
ericnicolaas / watch-apache
Created July 17, 2014 10:11
Keep track of the number of Apache processes and memory usage.
watch -n 1 "echo -n 'Apache Processes: ' && ps -C httpd --no-headers | wc -l && free -m"
/**
* Based on a single key, retrieve the data for a particular image, including whether it is retina and its dimensions.
*
* @param string $key
* @return false if not set, or array if set
* @access private
* @since 1.0
*/
private function get_image_data($key) {
$data = array();
@ericnicolaas
ericnicolaas / charitable-checkout-default-colour
Last active October 24, 2015 02:40
Set the default colour used by Charitable in the Checkout theme by Array.
<?php
/**
* Set the default colour used by Charitable.
*
* @return string
*/
function checkout_charitable_default_colour() {
return '#37BF91';
}
@ericnicolaas
ericnicolaas / charitable-change-campaign-link-in-loop
Last active October 26, 2015 01:28
Charitable campaign link in loop template
@ericnicolaas
ericnicolaas / stats.php
Created November 3, 2015 13:34
Reach child theme stats.php
<?php
/**
* Campaign stats.
*
* This is a variation of the default template provided in Reach. Instead of showing the percentage funded, it shows
* the actual funded amount. It also shows the goal amount.
*
* This should be saved to your-child-theme/charitable/campaign-loop/stats.php
*
* @package Reach