Skip to content

Instantly share code, notes, and snippets.

View rmpel's full-sized avatar

Remon Pel rmpel

View GitHub Profile
@rmpel
rmpel / wp-is-rest-call.php
Created June 27, 2017 13:28
WordPress detect rest_call
<?php
function is_rest_call() {
$domain = $_SERVER['HTTP_HOST'];
// filtered , maybe by WPML
$path = explode($domain, get_bloginfo('url'));
$lang_path = trailingslashit( $path[1] );
// this is /optional-subfolder/optional-language
// unfiltered
@rmpel
rmpel / wp.pot
Created July 14, 2017 07:40
blank Wordpress POT file
# WordPress Blank Pot
# Copyright (C) 2014 ...
# This file is distributed under the GNU General Public License v2 or later.
msgid ""
msgstr ""
"Project-Id-Version: MY_PROJECT\n"
"POT-Creation-Date: 2012-10-05 10:50+0100\n"
"PO-Revision-Date: \n"
"Last-Translator: Your Name <you@example.com>\n"
"Language-Team: Your Team <translations@example.com>\n"
@rmpel
rmpel / jquery.nlzipcodeinput.js
Created September 6, 2017 12:42
User friendly zip-code input, for DUTCH zip-codes. Gebruikersvriendelijke postcode invoer. (iOS getest)
(function($){
$.fn.input_zip = function(){
return $(this).on('keyup', function(e){
if ($(this).val().length >= 4) {
$(this).attr('inputmode', 'text');
$(this).attr('type', 'text');
}
else {
$(this).attr('inputmode', 'numeric');
$(this).attr('type', 'tel');
@rmpel
rmpel / .htaccess
Created October 2, 2017 09:12
.htaccess need secret keyword to view site otherwise get redirected
### Website offline per request, on oct 2, 2017 ###
SetEnvIf Request_URI "^/this-is-a-secret" BYPASS=bypass
RewriteRule ^this-is-a-secret / [R=302,CO=bypass-redirect:1:.secret-domain.com,L]
RewriteCond %{HTTP_COOKIE} bypass-redirect=1 [OR]
RewriteCond %{ENV:BYPASS} ^bypass$
RewriteRule .* - [S=1]
RewriteRule .* http://www.redirect-domain.com [R=301,L]
@rmpel
rmpel / converteer-30-naar-18-fps.sh
Created January 10, 2018 21:12
Slow down video from Super8 (18fps or 24fps) recorded as 30 fps.
#!/bin/bash
[ "" = "$1" ] && echo "Je bent vergeten het bron-bestand op te geven: $0 bron.mp4" && echo "Als tweede parameter kun je een doel-bestand opgeven: $0 bron.mp4 doel.mp4" && exit 1;
BRON="$1"
DOEL="$i"-18fps.mp4
[ "" != "$2" ] && DOEL="$2"
ffmpeg -i "$BRON" -r 18 -filter:v "setpts=(30/18)*PTS" "$DOEL"
@rmpel
rmpel / pfx-to-crt-and-key.sh
Created March 5, 2018 14:28 — forked from whereisaaron/pfx-to-crt-and-key.sh
Extract a crt file (PEM), key file, and chain bundle from a PFX file, prompts for password or use PFXPASSWORD environment variable
#!/bin/bash
#------------------
# Extract the key, certficiate, and chain in PEM format from a PFX format file
#
# Must supply the input pfx file
PFX_PATH="$1"
if [ "${PFX_PATH}" == "" ]; then
echo "Must supply pfx file path"
exit 1
@rmpel
rmpel / mu-plugin-do-not-track.php
Created May 3, 2018 11:57
Make Google Analytics listen to Browser "Do Not Track" in WordPress
<?php
add_filter('opt_out_settings', function($settings) {
// this will work in most sites with a plugin to use Google Analytics.
$settings['id'] = autodetect_google_analytics_code();
// OR!
// use this line to be sure;
$settings['id'] = 'UA-1234567-89'; // <-- your analytics property code here
@rmpel
rmpel / remove-sep.sql
Created May 15, 2018 08:40
Remove LSEP from database
update wp_posts SET post_title = REPLACE(post_title, UNHEX('e280a8'), '') WHERE post_title LIKE concat('%', UNHEX('e280a8'), '%');
update wp_posts SET post_content = REPLACE(post_content, UNHEX('e280a8'), '') WHERE post_content LIKE concat('%', UNHEX('e280a8'), '%');
@rmpel
rmpel / trim-deep.php
Created June 15, 2018 15:42
trim_deep
<?php
function trim_deep( &$array_object_or_scalar ) {
if (is_scalar($array_object_or_scalar)) {
$array_object_or_scalar = trim($array_object_or_scalar);
}
else if (is_array($array_object_or_scalar)) {
foreach ($array_object_or_scalar as &$item) {
trim_deep($item);
}
@rmpel
rmpel / in-your-application.php
Last active October 30, 2024 13:30
WordPress REST-API in website, NONCE problems when authenticating or de-authenticating (login / logout)
<?php
// sent an updated nonce to the front-end on each request
add_filter( 'rest_post_dispatch', function( WP_REST_Response $response, WP_REST_Server $rest, WP_REST_Request $request) {
$response->header('X-WP-Nonce', wp_create_nonce( 'wp_rest' ));
return $response;
}, PHP_INT_MAX, 3);
// wp_create_nonce relies on user-id from global user object, and authentication cookie.
// both are INCORRECT after programmatic log-in or log-out.
// Really, WordPress? You should do this for us!