Skip to content

Instantly share code, notes, and snippets.

Avatar

Marko Heijnen markoheijnen

View GitHub Profile
View gist:1fa920d41a6bbe6b7797
function get_props( description ) {
var users = [];
// Cleanup for easier parsing.
description = description.toLowerCase().replace( /[\n|, ]fixes(.*)/i, '' ).replace( /(\n|. )see(.*)/i, '' );
// Place enter to fix cases where it otherwise would fail. See changeset 22094
if ( '.' != description.substr(description.length - 1) ) {
description += '.';
}
@markoheijnen
markoheijnen / creator.php
Last active Aug 29, 2015
Favicon generator
View creator.php
<?php
class WP_Site_Icon_Creator {
private $file;
public function __construct() {
$this->file = dirname( __FILE__ ) . '/512px_Icon.png';
$this->generate();
}
@markoheijnen
markoheijnen / gist:aeae3d938d3b88608291
Last active Aug 29, 2015
Remove duplicated originals
View gist:aeae3d938d3b88608291
<?php
require_once dirname( dirname( __FILE__ ) ) . '/gp-load.php';
class GP_Script_Remove_Duplicated_Originals extends GP_CLI {
var $usage = "<path>";
public function run() {
if ( empty( $this->args ) ) {
$this->usage();
View gist:9337dc054e1224f9ba5b
- Set default language and all languages to WordPress/Babble
- Loop over all posts and load the translations inside post_content to an array
- Loop the array and skip the default language.
- Babble_Jobs->create_post_jobs( (object) $curren_post, (array) $language_codes )
- You will get post ids back and need to call the next function.
- Babble_Post_Public->initialise_translation( $original_post, $lang_code )
- For the behaviour it's best to look at Babble_Jobs->save_job() which is called by the save_post hook
- when successful the default language content should become post_content
View gist:577229cc5a22ca95915f
### Keybase proof
I hereby claim:
* I am markoheijnen on github.
* I am markoheijnen (https://keybase.io/markoheijnen) on keybase.
* I have a public key whose fingerprint is AEB9 B624 EABB AAC7 A40B 829E EAF4 86C8 5AE8 04C8
To claim this, I am signing this object:
@markoheijnen
markoheijnen / gist:41a17182c4a7d2608f62
Created Sep 23, 2014
Allow only one session per user.
View gist:41a17182c4a7d2608f62
<?php
add_action( 'wp_login', 'wp_destroy_other_sessions' );
@markoheijnen
markoheijnen / gist:1fb8aef0b3069d813ec7
Last active Aug 29, 2015
Cleaning up deprecated options in php.ini. Add this file in the root directory and call it from a browser. This script does the rest.
View gist:1fb8aef0b3069d813ec7
<?php
class PHP_Ini_Fixes {
private $deprecated_options = array(
// Can result in issue in different PHP versions
'browscap',
//PHP 5.4 removed
'register_globals', 'register_long_arrays',
'magic_quotes_gpc', 'magic_quotes_runtime', 'magic_quotes_sybase',
'allow_call_time_pass_reference',
@markoheijnen
markoheijnen / mysql_error_catcher.php
Last active Dec 20, 2015 — forked from kurtpayne/mysql_error_catcher.php
Custom error handler for catching MySQL errors
View mysql_error_catcher.php
<?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 / gist:6129265
Last active Feb 5, 2016
Fantastich ElasticSearch: add numeric meta key
View gist:6129265
<?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 / update-languages.sh
Last active Dec 16, 2015
Update all windows languages
View update-languages.sh
#!/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"