Skip to content

Instantly share code, notes, and snippets.

View Digiover's full-sized avatar
💭
☕️

Jan Reilink Digiover

💭
☕️
View GitHub Profile
@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 / 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 / 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 / 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 / cleanup-wordpress-database.sql
Created March 8, 2023 10:48
Clean up WordPress meta data, like comment and post meta. Don't forget to set your table prefix
-- Clean WordPress Post Meta Data
SELECT * FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;
DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;
-- Clean WordPress Comment Meta Data
SELECT * FROM wp_commentmeta WHERE comment_id NOT IN ( SELECT comment_id FROM wp_comments );
DELETE FROM wp_commentmeta WHERE comment_id NOT IN ( SELECT comment_id FROM wp_comments );
SELECT * FROM wp_commentmeta WHERE meta_key LIKE '%akismet%';
DELETE FROM wp_commentmeta WHERE meta_key LIKE '%akismet%';
@Digiover
Digiover / Ansible: Use a custom ssh config file
Created April 12, 2023 22:08
Configure and use a custom ssh config file with Ansible in Windows WSL 2
# Ansible can use a custom ssh config file if you configure its
# ANSIBLE_SSH_ARGS environment variable. Add to your `~/.bashrc`
#
# source: Windows 11/10 and WSL 2 DevOps environment
# - Sysadmins of the North
# https://www.saotn.org/windows-11-10-and-wsl-2-devops-environment/
#
export ANSIBLE_SSH_ARGS="-F ~/.ssh/wsl_config"
@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 / clear-opcode-caches.php
Last active January 27, 2024 14:05
WordPress: Clear PHP opcode caches before updates are applied, ease the updating process (https://www.saotn.org/wordpress-plugin-flush-php-opcache/)
<?php
/**
* Plugin Name: Clear PHP opcode caches
* Plugin URI: https://www.saotn.org/wordpress-plugin-flush-php-opcache/
* Donate URI: https://www.paypal.me/jreilink
* Description: Purges various PHP opcode and user caches. Currently it tries to clear / purge / flush PHP OPcache and WinCache caches from your web server's memory. This should ease WordPress updates and plugin activation / deactivation.
* Network: True
* Version: 1.2
* Author: Jan Reilink
* Author URI: https://www.saotn.org
@Digiover
Digiover / Import-PfxCertificateAutomation.ps1
Created June 7, 2023 08:21
Import a PFX certificate into Windows Server and change its FriendlyName property in PowerShell
# Import a PFX certificate into Windows Server and change its
# FriendlyName property in PowerShell.
#
# Using Get-Credential here ensures the password doesn't get saved
# into PowerShell's history file.
# -- see https://www.saotn.org for more PowerShell goodness :)
#
$CommonName = "CHANGEME"
$CertFileName = "CHANGEME.pfx"
@Digiover
Digiover / iis-discover-websites.ps1
Created February 6, 2024 09:34
Zabbix auto discovery for IIS websites
# Query Win32_PerfRawData_W3SVC_WebService for all metric labels (names), including all website names hosted in IIS
#
# The Web Service object includes counters specific to the World Wide Web Publishing Service.
(Get-CimInstance -EA SilentlyContinue -Query "select * from Win32_PerfRawData_W3SVC_WebService" -Namespace root\cimv2).Name
# https://www.saotn.org/monitor-website-performance-in-iis-with-zabbix/