Skip to content

Instantly share code, notes, and snippets.

View onnimonni's full-sized avatar

Onni Hakala onnimonni

View GitHub Profile
@onnimonni
onnimonni / functions.php
Created October 12, 2015 11:07
Child theme functions.php snippet which enqueues parent theme styles, loads languages from child theme and copies settings from parent theme to child theme.
<?php
/*
* Author: Onni Hakala / Seravo Oy
* Source: https://gist.github.com/onnimonni/8f58e72bc433c54f7b17
* Description: Use these default options which are good for every typical child theme
* You can just copy-paste this into child-theme functions.php
*/
if (!class_exists('ChildThemeOptions')) {
class ChildThemeOptions {
@onnimonni
onnimonni / source2pdf.sh
Created November 11, 2015 07:28
Wordpress project Source code to pdf in OS X
find . -type f \( -name "*.html" -or -name "*.css" -or -name "*.php" -or -name "*.js" -or -name "*.json" -or -name "*.yml" \) | cut -c 3- | while read line ; do echo $line; echo "---"; cat "$line"; echo "---"; echo ; done > all-code.txt && cupsfilter -D all-code.txt > code.pdf
@onnimonni
onnimonni / woocommerce-nosto-tagging.php
Created November 18, 2015 20:31
Nosto Woocommerce Relative urls fix
<?php
/*
Plugin Name: WooCommerce Nosto Tagging
Plugin URI: http://wordpress.org/extend/plugins/woocommerce-nosto-tagging/
Description: Implements the required tagging blocks for using Nosto marketing automation service.
Author: Nosto Solutions Ltd
Version: 1.0.4
License: GPLv2
*/
@onnimonni
onnimonni / simplified_wp_user_admin.php
Created January 13, 2016 13:29
Wordpress mu-plugin: Idea of this plugin is to reserve administrator roles only for developers and sys admins. This gives editor users ability to add new users. Removes authors and contributors and hides administrators from the user list.
<?php
/**
* Plugin Name: Simplified user roles
* Plugin URI: https://github.com/roots/bedrock/
* Description: Idea of this plugin is to reserve administrator roles only for developers and sys admins. Removes authors and contributors. Gives Editors capability to add new editors and subcsribers. Hides Administrators from editors.
* Version: 1.0.0
* Author: Onni Hakala
* Author URI: https://github.com/onnimonni
* License: MIT License
*/
@onnimonni
onnimonni / extract-site.sh
Created February 10, 2016 13:28
Script to extract wp-content + database of 1 single site out from the network.
#!/usr/bin/env bash
##
# Script for extracting single site from multisite
##
#SETUP
#static
wpdb="DATABASE NAME"
@onnimonni
onnimonni / rename-uploads.php
Created February 25, 2016 14:20
Remove accents from Wordpress uploads. This renames all files and replaces corresponding attachment in WordPress database. You probably use linux in production and might run OS X in development. This helps to avoid possible problems with filenames. To avoid this in future install mu-plugin which hooks in 'sanitize_file_name'
<?php
/*
* Replace-uploads.php
* This replaces all accents from your uploads
* you can run this with wp-cli: $ wp eval-file replace-uploads.php
*/
/**
* cd to right path before changes
*/
@onnimonni
onnimonni / remove-accents-on-upload.php
Last active February 26, 2018 11:02
Wordpress plugin which sanitizes files on upload. This fixes OS-X NFD characters as well if you have Normalizer class and icu library installed.
<?php
/**
* Plugin Name: Remove accents from files on upload
* Plugin URI: https://gist.github.com/onnimonni/d58bdcff44f8208a15c7
* Description: Sanitize accents from Cyrillic, German, French, Polish, Spanish, Hungarian, Czech, Greek, Swedish during upload. Also fix OS-X NFD filenames.
* Version: 1.0
* Author: Onni Hakala
* Author URI: http://github.com/onnimonni
* License: GPLv3
*/
@onnimonni
onnimonni / remove-accents-uploaded-files-and-database.php
Last active March 1, 2016 14:34
Run this file with wp-cli: $ wp eval-file remove-accents-uploaded-files-and-database.php to remove accents from all of your previous uploads. Also fix OS-X NFD filenames. After running this command install https://gist.github.com/onnimonni/d58bdcff44f8208a15c7 to your mu-plugins to avoid this in future uploads.
<?php
/**
* Sanitize accents from Cyrillic, German, French, Polish, Spanish, Hungarian, Czech, Greek, Swedish
* This replaces all accents from your uploads by renaming files and replacing attachment urls from database.
* This even removes NFD characters from OS-X by using Normalizer::normalize()
* This is one time script which you can use by running it with wp-cli:
* $ wp eval-file remove-accents-uploaded-files-and-database.php
*/
// Get all uploads
@onnimonni
onnimonni / self-signed-locally-trusted-ssl-certificates.md
Last active March 4, 2016 19:27
How to make self-signed certificates and how to add them trusted in your own machine. This is part of our automated dev environment: http://github.com/devgeniem/gdev

Self-trusted self-signed certificates for local development

You can repeat step 2 as many times and as many domains you like.

You need to have openssl installed.

-sha256 flag is needed to make chrome trust your new certificates as well.

STEP 1: Create CA certificate

@onnimonni
onnimonni / db-error.php
Created March 31, 2016 14:09
503 sivu wordpressin tietokantavirhe sivun tilalle
<?php
/**
* Custom error page rather than database connection error
* source: http://alexphelps.github.io/server-error-pages/
* translated by: Onni Hakala / Geniem Oy
*/
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 300'); // 5 minutes = 300 seconds