Skip to content

Instantly share code, notes, and snippets.

View efarem's full-sized avatar

EFAREM efarem

  • London, UK
View GitHub Profile
@efarem
efarem / WordPress Loop Shortcode
Last active December 15, 2015 07:19
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.
<?php
if (!class_exists('FRM_Loop'))
{
class FRM_Loop
{
public function __construct()
{
add_shortcode('loop', array(&$this, 'loop_shortcode'));
}
@efarem
efarem / Elapsed time string
Last active December 21, 2015 01:59
Convert a timestamp into a relative string e.g. 2 Hours ago
<?php
/**
* Convert a timestamp into a relative string e.g. 2 Hours ago
*
* @return string
*
* @param $time Timestamp
**/
function time_elapsed($time)
@efarem
efarem / ISO2 Country Codes
Last active January 16, 2016 09:51
A function to return a PHP array of ISO2 country codes. I use this a lot for HTML selects
<?php
/**
* An array of countries with ISO2 codes as key
*
* @return array
**/
function getCountries()
{
$options["AF"] = "Afghanistan";
@efarem
efarem / Resize Image Canvas
Created September 25, 2013 18:30
Quick and dirty was to resize an image canvas, center original and fill white space
<?php
function processImage($imgname)
{
// Load original image
$original = @imagecreatefromjpeg($imgname);
if (!$original)
die('Bad Image: ' . $imgname);
@efarem
efarem / Force HTTPS
Created September 30, 2013 08:57
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 / is_blog
Created October 1, 2013 15:45
WordPress function to tell if you're on a blog page, current page is a blog page
<?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 ;
@efarem
efarem / WooCommerce Payment Gateway
Created October 21, 2013 14:27
Basic template for WooCommerce Payment Gateway Class
<?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 / plesk-add-php
Last active December 31, 2015 15:29
Plesk - Add a new PHP version
/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 / php-configure
Last active December 31, 2015 15:29
PHP - Config pre build command
./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-reload-domain
Last active August 29, 2015 14:00
Plesk - Reload domain/vhost config
/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain example-domain.com