Skip to content

Instantly share code, notes, and snippets.

View Digiover's full-sized avatar
💭
☕️

Jan Reilink Digiover

💭
☕️
View GitHub Profile
@Digiover
Digiover / saotn-wpdb-optimizer.php
Last active June 7, 2023 08:35
Executes an OPTIMIZE TABLE statement on all WordPress MySQL database tables, for instance from within a plugin: https://www.saotn.org/optimize-wordpress-mysql-tables-cron/
/**
* Executes an OPTIMIZE TABLE statement on all WordPress database
* tables.
*/
public static function saotn_wpdb_optimizer() {
global $wpdb;
$tables = $wpdb->get_col( "SHOW TABLES" );
foreach ( $tables as $table ) {
$wpdb->query( "OPTIMIZE TABLE $table" );
}
@Digiover
Digiover / check-website-availability.php
Last active January 15, 2022 07:17
PHP/cURL function to check a web site status. If HTTP status is not 200 or 302, or the requests takes longer than 10 seconds, the website is unreachable. See https://www.saotn.org/php-curl-check-website-availability/.
<?php
/**
* PHP/cURL function to check a web site status. If HTTP status is not 200 or 302, or
* the requests takes longer than 10 seconds, the website is unreachable.
*
* Follow me on Twitter: @Jan_Reilink
*
* @param string $url URL that must be checked
*/
function url_test($url) {
@Digiover
Digiover / wp-database-tables-optimizer.php
Last active April 15, 2019 15:26
Optimizes WordPress database behind the scenes by executing an OPTIMIZE TABLE statement on all MySQL tables, 'daily' or 'hourly' as a WordPress Cron. More information @ https://www.saotn.org/optimize-wordpress-mysql-tables-cron/
<?php
/**
* Plugin Name: Saotn Database Table Optimizer
* Plugin URI: https://www.saotn.org
* Description: Optimizes WordPress database behind the scenes by executing an OPTIMIZE TABLE statement on all MySQL tables, 'daily' or 'hourly'. Please <a rel="nofollow" target="_blank" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=4EFPSXA623NZA" title="donate to Sysadmins of the North">donate $2.50 USD</a> through PayPal to support me in my research time and hosting costs.
* Version: 1.0.2
* Author: Jan Reilink
* Author URI: https://www.saotn.org
* License: GPLv2
*/
@Digiover
Digiover / Blacklistcheck.ps1
Last active January 15, 2022 07:17
Blacklistcheck.ps1 - checks an IP address in various blacklists (DNSBL, RBL), in PowerShell
# blacklistcheck.ps1 - PowerShell script to check
# an IP address blacklist status
#
# Follow me on Twitter: @Jan_Reilink
#
# Steps:
# 1. IPv4 IP address input from the command-line:
# .\blacklistcheck.ps1 1.2.3.4
# 2. reverse the IP address: 1.2.3.4 becomes 4.3.2.1
# 3. append the blacklist zone, e.g .cbl.abuseat.org.
@Digiover
Digiover / AdSense-in-WordPress.php
Last active January 15, 2022 07:17
Create Google AdSense shortcode for in WordPress
<?php
/*
* enqueue adsbygoogle.js in the footer &
* create a WordPress shortcode with your Google AdSense code
* follow me on Twitter: @Jan_Reilink
*/
function saotn_loadAdsByGoogleJs() {
wp_register_script( 'google-adsense', '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js', '', '', true );
wp_enqueue_script( 'google-adsense' );
@Digiover
Digiover / prefetch-prerender-posts.php
Last active January 15, 2022 07:16
Prefetch and prerender WordPress posts with a function hook add_action
<?php
function saotn_post_prerender_prefetch() {
/* follow me on Twitter: @Jan_Reilink */
$next_post = get_next_post();
$prev_post = get_previous_post();
if ( !empty( $next_post ) ) {
echo '<link rel="prefetch" href="'.get_permalink( $next_post->ID ).'" />
<link rel="prerender" href="'.get_permalink( $next_post->ID ).'" />';
}
if ( !empty( $prev_post ) ) {
@Digiover
Digiover / disable_php_script_execution.php
Last active January 15, 2022 07:16
Function to disable PHP script execution for WordPress wp-content/uploads folder
<?php
/**
* Disable PHP script execution for WordPress wp-content/uploads folder.
* - based off the WordPress permalinks rewrite code
*
* - https://www.saotn.org/secure-wordpress-uploads-folder-disable-php-execution/
* - follow me on twitter: @Jan_Reilink
*
* don't allow this file to be loaded directly
*/
@Digiover
Digiover / add-hsts-to-wordpress.php
Last active January 15, 2022 07:15
Add HSTS to WordPress using a send_headers action
<?php
/*
* https://www.saotn.org/enable-http-strict-transport-security-hsts-on-iis/
* follow me on Twitter: @Jan_Reilink
*/
add_action( 'send_headers', 'saotn_add_hsts_header' );
function saotn_add_hsts_header() {
header( 'Strict-Transport-Security: max-age=31536000; includeSubDomains; preload' );
}
@Digiover
Digiover / cache_enabler_disk.class.php.patch
Created October 25, 2016 09:42
Diff for cache_enabler_disk.class.php to add wp_is_mobile() support to KeyCDN's Cache Enabler plugin
--- cache_enabler_disk.class.php.org 2016-09-26 07:24:22.000000000 +0200
+++ cache_enabler_disk.class.php 2016-10-24 16:33:54.145108306 +0200
@@ -24,7 +24,9 @@
*/
const FILE_HTML = 'index.html';
+ const FILE_HTML_MOBILE = 'index-mobile.html';
const FILE_GZIP = 'index.html.gz';
+ const FILE_GZIP_MOBILE = 'index-mobile.html.gz';
const FILE_WEBP_HTML = 'index-webp.html';
@Digiover
Digiover / make-readonly.php
Last active November 23, 2016 17:26
Make WordPress writable before, and read-only after, WordPress updates with this MU-Plugin
<?php
/**
* Plugin Name: Make Read Only &amp; Clear Read Only WordPress
* Plugin URI: https://www.saotn.org
* Description: Makes all WordPress files read-only after updates, and writable just before updates. This should ease WordPress updates when it's read-only on the file system. Please donate <a rel="nofollow" target="_blank" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=J24FGGU96YSUY" title="donate to Sysadmins of the North in Dollars">$2.50 USD</a> (or <a rel="nofollow" target="_blank" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=QLX4RPPL3L8LY" title="donate to Sysadmins of the North in Euros">&euro; 2,50 Euro</a>) through PayPal to support me in my research time and hosting costs.
* Network: True
* Version: 1.0
* Author: Jan Reilink
* Author URI: https://www.saotn.org
* License: GPLv2