Warn users before they exit a form

document.addEventListener(‘DOMContentLoaded’, function(){     function exitWarning(e){         e.preventDefault();     }     function setExitWarning(){         window.addEventListener(‘beforeunload’, exitWarning );         this.removeEventListener(‘change’, setExitWarning );     }     var forms = document.querySelectorAll(‘main form’);          for ( var i = 0, l = forms.length; i < l; i++ ) {         forms[i].addEventListener(‘change’, setExitWarning );    […]

Using UTM parameters in forms and anywhere shortcodes can be used

// Shortcode for retrieving Session params if ( ! shortcode_exists(‘get_cookie’) ) { function readycat_get_cookie( $atts ) { // check for shortcode param if ( empty( $atts[‘key’] ) ) return ‘Please specify a key=whatever_value in the shortcode.’; $default = !empty( $atts[‘default’] ) ? $atts[‘default’] : ”; if ( ! empty( $_GET[ $atts[‘key’] ] ) ) { […]

Setting up a radio with IceCast and EZstream

hostnamectl set-hostname radio nano /etc/hosts apt-get update && apt-get -y dist-upgrade && apt-get -y install gcc libcurl4-gnutls-dev libvorbis-dev libxslt1-dev pkg-config libtheora-dev libspeex-dev openssl last 3 are optional (libtheora-dev libspeex-dev openssl), not sure about pkg-config cd /usr/src/ wget http://downloads.xiph.org/releases/icecast/icecast-2.4.3.tar.gz tar -xzvf icecast-2.4.3.tar.gz cd icecast-2.4.3/ ./configure make make install # libshout cd /usr/src/ wget http://downloads.xiph.org/releases/libshout/libshout-2.4.1.tar.gz tar -xzvf […]

Running your own Mail Server with iRedMail

apt-get update && apt-get -y dist-upgrade && apt-get clean hostnamectl set-hostname mail nano /etc/hosts hostname # get latest download link from http://www.iredmail.org/download.html wget https://bitbucket.org/zhb/iredmail/downloads/iRedMail-0.9.5-1.tar.bz2 tar jxf iRedMail-0.9.5-1.tar.bz2 cd iRedMail-0.9.5-1/ bash iRedMail.sh # long wait reboot amavisd-new showkeys # install dkim in domains DNS, name=dkim._domainkey type=TXT value=”v=DKIM1; p=k32hkj…” (remove the quotes and spaces at line breaks) […]

WordPress Debugging

define( ‘WP_DEBUG’, true ); if ( WP_DEBUG ) { define( ‘WP_DEBUG_DISPLAY’, false ); define( ‘WP_DEBUG_LOG’, true ); @ini_set( ‘display_errors’, 0 ); define( ‘SCRIPT_DEBUG’, true ); }

Wordpress Sitemaps: disable, remove users, add lastmod

Wordpress 5.5 shipped with sitemaps enabled by default.  This quite possibly isn’t a good thing. Disable them entirely add_filter( ‘wp_sitemaps_enabled’, ‘__return_false’ ); Disable just the Users sitemap add_filter( ‘wp_sitemaps_add_provider’, function( $prov, $name ) { return ‘users’ === $name ? false : $prov; }, 10, 2 ); <lastmod> If you do want them, you may want […]

Remove URL slug from custom post type

Two functions, first one removes the slug from links throughout the site. Second one adds the custom post type to the query, so that it looks for the name in both regular posts and custom post type. function remove_cpt_slug( $link, $post ) { if ( ‘my_post_type’ === $post->post_type ) { $link = str_replace( ‘/’ . […]

Redirect entire site to a new domain with apache rewrite

Just put one of these rultes at the top of your .htaccess file. Pick your favorite. RedirectMatch 301 ^(.*) https://newdomain.com$1 RewriteRule ^(.*) https://newdomain.com$1 [R=301,L] RewriteRule ^ https://newdomain.com%{REQUEST_URI} [R=301,L] If you still want access to something (say adminer so you can check on the old database and to last minute stuff) use a RewriteRule method and […]

Wordpress logs you out at inconvenient times

It’s annoying to be signed out in the middle of your work. The default keeps you logged in for 2 weeks, and a lot of suggestions for changing this time use a multiple of 24 hours… so you’re always trapped in a cycle of getting logged out during working hours. (Say you log in monday […]

VS Code doesn’t select the $$$

When using Microsoft Visual Studio Code / Monaco for PHP it’s really annoying to me how double-clicking a variable doesn’t include the dollar sign in the selection. Go to the settings and search for editor.wordSeparators: Word Separators Characters that will be used as word separators when doing word related navigations or operations. You can simply […]