Skip to content

Instantly share code, notes, and snippets.

View markoheijnen's full-sized avatar

Marko Heijnen markoheijnen

View GitHub Profile
@markoheijnen
markoheijnen / gist:1fb8aef0b3069d813ec7
Last active August 29, 2015 14:06
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.
<?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 / gist:41a17182c4a7d2608f62
Created September 23, 2014 19:17
Allow only one session per user.
<?php
add_action( 'wp_login', 'wp_destroy_other_sessions' );
### 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:9337dc054e1224f9ba5b
Created November 19, 2014 20:11
qTranslate to Babble
- 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
@markoheijnen
markoheijnen / gist:aeae3d938d3b88608291
Last active August 29, 2015 14:10
Remove duplicated originals
<?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();
@markoheijnen
markoheijnen / creator.php
Last active August 29, 2015 14:23
Favicon generator
<?php
class WP_Site_Icon_Creator {
private $file;
public function __construct() {
$this->file = dirname( __FILE__ ) . '/512px_Icon.png';
$this->generate();
}
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 / gist:2215557
Created March 27, 2012 12:53
Create span on last character of WordPress title
<?php
$string = get_the_title();
$last_character = $string[ strlen( $string ) - 1 ];
echo substr( $string, 0, -1 ) . '<span>' . $last_character . '</span>';
?>
@markoheijnen
markoheijnen / gist:2355637
Created April 10, 2012 23:36
Create a WordPress page without a database entry
<?php
add_action( 'generate_rewrite_rules', 'specialpage_rewrite' );
function specialpage_rewrite( $wp_rewrite ) {
$extra_rules = array(
'special-page/?$' => 'index.php?show_special_page=1',
);
$wp_rewrite->rules = $extra_rules + $wp_rewrite->rules;
@markoheijnen
markoheijnen / gist:2572299
Created May 1, 2012 23:16
Adding post type to the Recent post widget to WordPress 3.4+
<?php
add_action( 'in_widget_form', 'extend_recent_posts_form', 10, 3 );
add_filter( 'widget_update_callback', 'extend_recent_posts_update', 10, 4 );
add_filter( 'widget_title', 'extend_recent_posts_init_query_filter', 10, 3 );
add_filter( 'widget_posts_args', 'extend_recent_posts_query' );
function extend_recent_posts_form( $widget, $return, $instance ) {
if( ! is_a( $widget, 'WP_Widget_Recent_Posts' ) )
return;