Skip to content

Instantly share code, notes, and snippets.

View pdewouters's full-sized avatar
🌄
Working from home

Paul de Wouters pdewouters

🌄
Working from home
View GitHub Profile
@pdewouters
pdewouters / gist:7378767
Created November 8, 2013 22:33
change plugin active order
// Push Gravity Forms to the top of the list of plugins to make sure it's loaded before any add-ons
add_action("activated_plugin", array("GFForms", "load_first"));
}
public static function load_first() {
$plugin_path = basename(dirname(__FILE__)) . "/gravityforms.php";
$active_plugins = get_option('active_plugins');
$key = array_search($plugin_path, $active_plugins);
if ($key > 0) {
array_splice($active_plugins, $key, 1);
@pdewouters
pdewouters / gist:7374687
Created November 8, 2013 17:38
Returns the parent and child term slugs separated by a slash `parent-slug/child-slug`
SELECT CONCAT(parents.parent_slug, '/', children.slug) AS slug
FROM
(
SELECT distinct t.term_id ,t.slug AS parent_slug
FROM wp_term_taxonomy AS tt
INNER JOIN wp_terms AS t
ON tt.parent = t.term_id
) parents
INNER JOIN
(
@pdewouters
pdewouters / gist:6948006
Last active December 25, 2015 08:39
reload ajax content in prettyphoto
(function ($) {
"use strict";
$(function () {
$("a[rel^='contactPopup']").prettyPhoto({social_tools: false});
jQuery(document).bind('gform_post_render', function(){
$.prettyPhoto.open('#data');
});
$my_front_page = function() {
if ( 'page' !== get_option( 'show_on_front' ) )
return;
$homepage = get_page_by_path( 'home' );
// check that $homepage returned something
return $homepage->ID;
}
add_filter( 'pre_option_page_on_front', $my_front_page );
@pdewouters
pdewouters / gist:6570225
Created September 15, 2013 12:08
remove byline from Spine2
function mychildtheme_byline( $html ){
return '';
}
add_filter('entry_byline', 'mychildtheme_byline' );
@pdewouters
pdewouters / gist:6550105
Created September 13, 2013 12:36
If you don't use a try...catch block, and no error handler it's the same as no error handler with the try...catch blocks
<?php
/**
* Class Arr_Test
*/
class Arr_Test {
/**
* Gives us a property to play with
* @var array
@pdewouters
pdewouters / gist:6550083
Last active December 22, 2015 23:59
If you don't define the custom error handler, the application with fatal error: `PHP Catchable fatal error: Argument 1 passed to Arr_Test::__construct() must be of the type array, string given`
<?php
/**
* Class Arr_Test
*/
class Arr_Test {
/**
* Gives us a property to play with
* @var array
@pdewouters
pdewouters / gist:6550033
Last active December 22, 2015 23:58
In this case, we remove the type hinting, leaving a default value of an empty array. If another type is passed, the code may not fail but will cause unexpected results. Notice the extra if statements I added in the processing function to check if the property is an array and it's not empty. With type hinting we can catch this much earlier in the…
<?php
/**
* Custom Error Handler for E_RECOVERABLE_ERROR
*
* http://stackoverflow.com/a/2468534/285564
*
* @param $errno
* @param $errstr
* @param $errfile
@pdewouters
pdewouters / gist:6550014
Created September 13, 2013 12:27
In this case, we give the parameter a default value of an empty array. This makes it optional, meaning the code should run fine without a parameter
<?php
/**
* Custom Error Handler for E_RECOVERABLE_ERROR
*
* http://stackoverflow.com/a/2468534/285564
*
* @param $errno
* @param $errstr
* @param $errfile
@pdewouters
pdewouters / gist:6549934
Last active December 22, 2015 23:49
This example passes a string value as a parameter to the constructor which expects an array. It catches the error and can decide what to do. The parameter is required.
<?php
/**
* Custom Error Handler for E_RECOVERABLE_ERROR
*
* http://stackoverflow.com/a/2468534/285564
*
* @param $errno
* @param $errstr
* @param $errfile