Skip to content

Instantly share code, notes, and snippets.

@k1sul1
k1sul1 / ACF-json to array
Last active January 8, 2016 12:35
"Convert" ACF field group json dumps to php array syntax.
<?php
$json = '[{"key":"group_5533906b7cb6f","title":"Kirja-arviot","fields":[{"key":"field_54f96fb0b6afd","label":"Kirjan nimi","name":"kirja-nimi","type":"text","instructions":"","required":0,"conditional_logic":0,"wrapper":{"width":"","class":"","id":""},"default_value":"","placeholder":"","prepend":"","append":"","formatting":"html","maxlength":"","readonly":0,"disabled":0},{"key":"field_54f97431afa89","label":"Kirjan kuva","name":"kirja-kuva","type":"image","instructions":"","required":0,"conditional_logic":0,"wrapper":{"width":"","class":"","id":""},"preview_size":"thumbnail","library":"all","return_format":"array","min_width":0,"min_height":0,"min_size":0,"max_width":0,"max_height":0,"max_size":0,"mime_types":""},{"key":"field_54f9728eb6b00","label":"Kirjan tiedot","name":"kirja-tiedot","type":"repeater","instructions":"Esimerkiksi julkaisija, kirjan kuvaus tai julkaisuvuosi.","required":0,"conditional_logic":0,"wrapper":{"width":"","class":"","id":""},"row_min":"","row_limit":"","layout":"table","but
@k1sul1
k1sul1 / wp_check_for_vulnerabilities.php
Last active January 21, 2016 13:52
Short snippet to use with WPScan, discards all unnecessary data and prints only the alarming fields.
// pipe script output to this script:
// ./wpscan --url=http://site.fi | php wp_check_for_vulnerabilities.php
$error = false;
while(!feof(STDIN)){
$line = fgets(STDIN);
if(strpos($line,"[!]")){
echo $line;
$error = true;
<?php
$dryRun = true;
$posts = get_posts(array("post_type" => (!empty($_GET['type']) ? $_GET['type'] : 'post'), "posts_per_page" => -1)); // post_type is kinda reserved.
foreach($posts as $post){
$id = $post->ID;
if(has_post_thumbnail($id)){
continue;
@k1sul1
k1sul1 / remove-accents-on-upload.php
Created February 25, 2016 17:43 — forked from onnimonni/remove-accents-on-upload.php
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
*/
@k1sul1
k1sul1 / bbpress-votes-hidepost.js
Last active March 8, 2016 10:01
bbPress Votes hide post if score is below threshold
(function () {
"use strict";
// ES6 Magic, powered by Babel.
if (document.body.classList.contains("bbpress")) {
var replies = document.querySelectorAll(".reply");
for (var i = 0; i < replies.length; i++) {
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",
@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");
@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 / 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 / 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){},