Skip to content

Instantly share code, notes, and snippets.

View rmpel's full-sized avatar

Remon Pel rmpel

View GitHub Profile
@rmpel
rmpel / apache_request_headers.php
Last active June 11, 2022 09:30
apache_request_headers drop-in function for PHP as FPM
<?php
// Drop-in replacement for apache_request_headers() when it's not available
if ( ! function_exists( 'apache_request_headers' ) ) {
function apache_request_headers() {
static $arrHttpHeaders;
if ( ! $arrHttpHeaders ) {
// Based on: http://www.iana.org/assignments/message-headers/message-headers.xml#perm-headers
$arrCasedHeaders = array(
@rmpel
rmpel / rba.sh
Created November 30, 2016 10:27
Apache Config File builder - generates an Apache2 config file based on a Development directory with virtual hosts with custom TLD.
#!/bin/bash
# this file is related to a series of posts on my website, see
# https://remonpel.nl/2012/10/semi-automatically-rebuild-apache-vhost-configuration/
# this script is ANYTHING BUT optimal
# it works as it is very well on macOS, Ubuntu and "Bash on Ubuntu on Windows with WSL"
# WSL is a seriously crippled way to use anything linux related, but if you are brave enough, you should try it.
# If you have better ways of doing things, send me a note :)
@rmpel
rmpel / divi__all_templates_on_all_post_types.php
Created December 1, 2016 16:37
Use DIVI Page-Builder templates Globally - ALWAYS. With this, all post types use the same pool of section templates
<?php
/**
* Adds a divi builder to given custom post types and globalize all section templates
*
* @return array All post-type-names
* @uses get_post_types()
*/
function divi_overrule_post_types() {
return get_post_types();
}
@rmpel
rmpel / wpcf7-helper--link-checkbox-label.php
Last active December 2, 2016 11:12
WPCF7 helper: make a checkbox label partially linking, WordPress shortcode
@rmpel
rmpel / wp-paginate-2.0.0-input-field-fix.patch
Created January 18, 2017 09:04
wp-paginate by MaxFoundry version 2.0.0 - input field fix
--- wp-paginate.php 2017-01-18 09:54:43.000000000 +0100
+++ wp-paginate-fixed.php 2017-01-18 10:00:56.000000000 +0100
@@ -537,17 +537,17 @@
<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e('Pagination Label:', 'wp-paginate'); ?></th>
- <td><input name="title" type="text" id="title" size="40" value="<?php echo stripslashes(htmlspecialchars($this->options['title'])); ?>"/>
+ <td><input name="title" type="text" id="title" size="40" value="<?php echo esc_attr(stripslashes(htmlspecialchars($this->options['title']))); ?>"/>
<span class="description"><?php _e('The optional text/HTML to display before the list of pages.', 'wp-paginate'); ?></span></td>
</tr>
@rmpel
rmpel / add_wp_image_id_class.php
Created February 2, 2017 13:04
Add wp-image-ID class to images in content without them, as long as they are a WP upload. (UNTESTED!)
<?php
function wp_add_image_id_to_img_tags( $content ) {
if ( ! preg_match_all( '/<img [^>]+>/', $content, $matches ) ) {
return $content;
}
$selected_images = array();
/*array*/$uploads = wp_upload_dir();
/*fullpath*/$uploads = $uploads['basedir'];
@rmpel
rmpel / emr-do-more.php
Created February 28, 2017 16:10
Update more meta when Enable Media Replace replaces a file
<?php
// this gist is an example for updating a custom array-meta-data whenever EMR replaces a media file and renames it.
add_action('enable-media-replace-upload-done', 'more_to_do_emr');
function more_to_do_emr( $new_guid ) {
global $wpdb;
// get attachments meta data
$attachment_id = (int) $_POST["ID"];
if (!$attachment_id)
return;
$meta_ids = $wpdb->get_col("SELECT meta_id FROM {$wpdb->postmeta} where meta_key = 'attachments' AND meta_value LIKE '%i:{$attachment_id};%'");
@rmpel
rmpel / wp-error-log-in-wp-config.php
Last active March 1, 2017 12:52
WordPress Database error_log; white errors to database instead of server error_log. Quite useful in case you don't have (easy) access to your error_log
<?php
// put this below the database definitions and the $table_prefix line in wp-config.php.
// functionnames are random hashes to prevent with almost certainty any conflict.
// this is not intended as security by obscurity, the original functionnames are in comment
// requires PDO
// written for wordpress, but easily adapted for use in any other PHP framework.
function func46CA242BADDB4B579F2BC69A4BF300AB($set=null) { // store_or_get_error_handler_name
static $error_handler;
@rmpel
rmpel / localstorage-wrapper-incognito.js
Created May 5, 2017 09:10
LocalStorage/SessionStorage in Incognito detectie (dutch version)
var localStorageEnabled = false;
if ('localStorage' in window) {
localStorageEnabled = true;
try {
localStorage.setItem('localStorage', 1);
localStorage.removeItem('localStorage');
} catch (e) {
localStorageEnabled = false;
Storage.prototype._setItem = Storage.prototype.setItem;
Storage.prototype.setItem = function() {};
@rmpel
rmpel / dbsar
Last active April 20, 2020 13:42
dbsar - db-search-and-replace - a fork of "Safe Search and Replace on Database with Serialized Data v2.2.0" by InterconnectIt, made into a command-line utility.
#!/usr/bin/env php
<?php
ini_set('memory_limit', '256M');
if (isset($_SERVER) && isset($_SERVER['HTTP_HOST'])) {
die('CLI only!');
}
$pwd = getcwd();