Skip to content

Instantly share code, notes, and snippets.

Avatar

Frank Martin efarem

  • Improbable
  • London, UK
View GitHub Profile
@efarem
efarem / convert-apache-php-fpm
Created May 24, 2016
Convert Apache to PHP-FPM
View convert-apache-php-fpm
#!/bin/bash
# Install dependencies
sudo apt-get install -y apache2-mpm-worker
sudo apt-get install -y libapache2-mod-fastcgi php5-fpm
# Disable prefork & Enable fcgi
sudo a2dismod php5 mpm_prefork
sudo a2enmod actions fastcgi alias mpm_worker
@efarem
efarem / WooCommerce Payment Gateway
Created Oct 21, 2013
Basic template for WooCommerce Payment Gateway Class
View WooCommerce Payment Gateway
<?php
class WC_Gateway_EFAREM extends WC_Payment_Gateway
{
public function __construct()
{
$this->id = 'efarem';
$this->icon = plugin_dir_url(__FILE__) . '/assets/images/efarem.png';
$this->has_fields = true;
$this->method_title = '{Title of Gateway}';
@efarem
efarem / ISO2 Country Codes
Last active Jan 16, 2016
A function to return a PHP array of ISO2 country codes. I use this a lot for HTML selects
View ISO2 Country Codes
<?php
/**
* An array of countries with ISO2 codes as key
*
* @return array
**/
function getCountries()
{
$options["AF"] = "Afghanistan";
@efarem
efarem / php-configure
Last active Dec 31, 2015
PHP - Config pre build command
View php-configure
./configure --prefix=/usr/local/src/php-5.4.23 --with-config-file-path=/usr/local/src/php-5.4.23/lib/php.ini --enable-cgi --enable-soap --with-pdo-mysql --with-curl --with-mysql --with-openssl --enable-force-cgi-redirect
@efarem
efarem / plesk-add-php
Last active Dec 31, 2015
Plesk - Add a new PHP version
View plesk-add-php
/usr/local/psa/bin/php_handler --add -id "5.4.23" -displayname "5.4.23" -path /usr/local/src/php-5.4.23/bin/php -phpini /usr/local/src/php-5.4.23/lib/php.ini -type "fastcgi"
@efarem
efarem / is_blog
Created Oct 1, 2013
WordPress function to tell if you're on a blog page, current page is a blog page
View is_blog
<?php
/**
* Are we on a blog page?
*
* @return bool
**/
function is_blog()
{
return (is_post_type_archive('post') || is_author() || is_category() || is_home() || is_singular('post') || is_tag()) ? true : false ;
View Force HTTPS
if (!isset($_SERVER['HTTPS']))
{
header('Status-Code: 301');
header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
}
else
{
header('Strict-Transport-Security: max-age=500');
}
@efarem
efarem / Resize Image Canvas
Created Sep 25, 2013
Quick and dirty was to resize an image canvas, center original and fill white space
View Resize Image Canvas
<?php
function processImage($imgname)
{
// Load original image
$original = @imagecreatefromjpeg($imgname);
if (!$original)
die('Bad Image: ' . $imgname);
@efarem
efarem / Elapsed time string
Last active Dec 21, 2015
Convert a timestamp into a relative string e.g. 2 Hours ago
View Elapsed time string
<?php
/**
* Convert a timestamp into a relative string e.g. 2 Hours ago
*
* @return string
*
* @param $time Timestamp
**/
function time_elapsed($time)
@efarem
efarem / WordPress Loop Shortcode
Last active Dec 15, 2015
WordPress loop shortcode, super useful for when you're faking post type archives using pages for SEO or for adding content above and below easily.
View WordPress Loop Shortcode
<?php
if (!class_exists('FRM_Loop'))
{
class FRM_Loop
{
public function __construct()
{
add_shortcode('loop', array(&$this, 'loop_shortcode'));
}
You can’t perform that action at this time.