Skip to content

Instantly share code, notes, and snippets.

View markoheijnen's full-sized avatar

Marko Heijnen markoheijnen

View GitHub Profile
@markoheijnen
markoheijnen / gist:2399864
Created April 16, 2012 16:40
Change Post to News
<?php
add_action( 'init', array( &$this, 'change_post_object_label' ), 0 );
add_action( 'admin_menu', array( &$this, 'change_post_menu_label' ), 0 );
add_filter( 'post_updated_messages', array( &$this, 'post_updated_messages') );
function change_post_menu_label() {
global $menu;
global $submenu;
if( isset( $menu[5], $submenu['edit.php'] ) ) {
@markoheijnen
markoheijnen / gist:2407319
Created April 17, 2012 16:29
Get WordPress menu title by theme location
<?
function get_menu_title( $theme_location, $default_name = 'menu' ) {
if ( $theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $theme_location ] ) ) {
$menu = wp_get_nav_menu_object( $locations[ $theme_location ] );
if( $menu && $menu->name ) {
return $menu->name;
}
}
@markoheijnen
markoheijnen / gist:2399898
Created April 16, 2012 16:46
Updating CDN when it is activated and the site using W3 Total cache
<?php
$cdn_activated = false;
if( function_exists( 'w3_instance' ) ) {
$cdn_activated = w3_instance('W3_Config')->get_boolean( 'cdn.enabled' );
@set_time_limit( w3_instance('W3_Config')->get_integer('timelimit.cdn_import') );
}
$upload_dir = wp_upload_dir();
$file = 'test/somefile.png';
$new_location = $upload_dir[ 'baseurl' ] . $file;
@markoheijnen
markoheijnen / gist:2606505
Created May 6, 2012 00:15
Cool way to include jquery from google on WordPress
<?php
class Load_External {
private $jquery_path;
private function load_external_jquery() {
global $wp_scripts;
$schema = is_ssl() ? 'https://' : 'http://';
@markoheijnen
markoheijnen / gist:2576124
Created May 2, 2012 12:07
Class to enable a nice way to let the user have a horizontal sidebar
<?php
class Sidebar_Horizontal {
public $end_row = '<div class="clearfix"></div>';
private $registered = array();
private $counter = array();
function __construct() {
add_filter( 'dynamic_sidebar_params', array( &$this, '_sidebar_params' ) );
@markoheijnen
markoheijnen / gist:6129265
Last active February 5, 2016 11:07
Fantastich ElasticSearch: add numeric meta key
<?php
class My_Elasticsearch {
public function __construct() {
add_filter( 'elasticsearch_config_facets', array( $this, 'add_facets' ) );
add_filter( 'elasticsearch_config_fields', array( $this, 'add_fields' ) );
add_filter( 'elasticsearch_indexer_map_field', array( $this, 'indexer_map_field' ), 10, 2 );
add_filter( 'elasticsearch_indexer_build_document', array( $this, 'indexer_build_document' ), 10, 2 );
}
@markoheijnen
markoheijnen / mysql_error_catcher.php
Last active December 20, 2015 15:59 — forked from kurtpayne/mysql_error_catcher.php
Custom error handler for catching MySQL errors
<?php
function wp_set_error_handler() {
if ( defined( 'E_DEPRECATED' ) )
$errcontext = E_WARNING | E_DEPRECATED;
else
$errcontext = E_WARNING;
set_error_handler( function( $errno, $errstr, $errfile ) {
if ( 'wp-db.php' !== basename( $errfile ) ) {
@markoheijnen
markoheijnen / update-languages.sh
Last active December 16, 2015 17:18
Update all windows languages
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
LANGUAGES=(
"de:WordPress/Localization/LocalizedResources.de-DE.resx"
"es:WordPress/Localization/LocalizedResources.es-ES.resx"
"it:WordPress/Localization/LocalizedResources.it-IT.resx"
"ja:WordPress/Localization/LocalizedResources.ja-JP.resx"
"nl:WordPress/Localization/LocalizedResources.nl.resx"
@markoheijnen
markoheijnen / gist:5312334
Last active December 15, 2015 19:38
Structure example for deprecated methods
Index: tests/image/size.php
===================================================================
--- tests/image/size.php (revision 1257)
+++ tests/image/size.php (working copy)
@@ -95,57 +95,6 @@
$this->assertequals(array(525, 700), $out);
}
- function test_shrink_dimensions_default() {
- $out = wp_shrink_dimensions(640, 480);
@markoheijnen
markoheijnen / gist:5304289
Created April 3, 2013 19:08
update of /tests/image/resize.php
Index: tests/image/resize.php
===================================================================
--- tests/image/resize.php (revision 1254)
+++ tests/image/resize.php (working copy)
@@ -6,107 +6,114 @@
* @group upload
*/
abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase {
- // image_resize( $file, $max_w, $max_h, $crop=false, $suffix=null, $dest_path=null, $jpeg_quality=75)