Skip to content

Instantly share code, notes, and snippets.

@hanicker
hanicker / wc-prevent-checkout-for-cart-with-specific-category.php
Created November 28, 2020 15:38 — forked from bekarice/wc-prevent-checkout-for-cart-with-specific-category.php
Prevents checkout if the WooCommerce cart only contains items from a specific category
<?php // only copy this line if needed
/**
* Renders a notice and prevents checkout if the cart
* only contains products in a specific category
*/
function sv_wc_prevent_checkout_for_category() {
// set the slug of the category for which we disallow checkout
$category = 'clothing';
@hanicker
hanicker / create-wp-admin.php
Created July 27, 2020 07:06 — forked from maddisondesigns/create-wp-admin.php
Create a new WordPress Administrator User
<?php
// ADD NEW ADMIN USER TO WORDPRESS
// ----------------------------------
// Put this file in your Wordpress root directory and run it from your browser.
// Delete it when you're done.
// Original script by Joshua Winn - https://joshuawinn.com/create-a-new-wordpress-admin-user-from-php
require_once('wp-blog-header.php');
require_once('wp-includes/registration.php');
@hanicker
hanicker / wpseo-yoast-sitemap-custom.php
Created July 25, 2020 19:58 — forked from leepowers/wpseo-yoast-sitemap-custom.php
WordPress Yoast SEO: Create a custom sitemap with data not sourced from a custom post type.
<?php
/**
* USAGE:
* - Search and replace the `CUSTOM_SITEMAP` string with a lowercase identifier name: e.g., "vehicles", "customer_profiles"
* - The `your_alternate_data_source()` function does not exist; it's simply a placeholder for your own function that returns some sort of data array.
* - Uses heredocs for inline XML: https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
*/
/**
@hanicker
hanicker / wpseo-yoast-sitemap-post-types.php
Created July 25, 2020 19:57 — forked from leepowers/wpseo-yoast-sitemap-post-types.php
WordPress Yoast SEO: Custom sitemap with data sourced from one or more post types
<?php
/**
* USAGE:
* - Configure the return value of the `CUSTOM_SITEMAP_post_types` to required post type(s) - otherwise populates sitemap with all posts and pages
* - Search and replace the `CUSTOM_SITEMAP` string with a lowercase identifier name: e.g., "myseo", "vehicles", "customer_profiles", "postspage", etc.
* - Uses heredocs for inline XML: https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
*/
/**
@hanicker
hanicker / PS2Scancode.ino
Created March 30, 2020 17:32 — forked from DorianRudolph/LICENSE.txt
Arduino PS2 to USB HID Keyboard Converter
//Program that outputs all PS2 scancodes via serial
#define BUFFER_SIZE 45
static volatile uint8_t buffer[BUFFER_SIZE];
static volatile uint8_t head, tail;
#define DATA_PIN 10
#define IRQ_PIN 3
// The ISR for the external interrupt
@hanicker
hanicker / archive-commit.bat
Created December 5, 2019 01:05 — forked from hereswhatidid/archive-commit.bat
Create a zip archive of a specific commit. The archive will be named deploy/deploy-COMMITID.zip.
setlocal enabledelayedexpansion
set var=%1
set output=
for /f "delims=" %%a in ('git diff-tree --no-commit-id --name-only -r %1^^') do ( set output=!output! "%%a" )
git archive -o update-%var:~0,7%.zip HEAD %output%
endlocal
@hanicker
hanicker / gist:13754f5acca0249ff544da3c862aa02d
Created September 23, 2019 07:05
wp-performance-debug.php
<?php
add_action( 'all', 'log_hook_calls' );
function log_hook_calls() {
// Restrict logging to requests from your IP - your IP address goes here
$client_ip = "123.123.123.123";
// The full path to your log file:
$upd = wp_upload_dir();
$log_file_path = $upd['basedir']."/log-hook-calls.log";
if ($_SERVER['REMOTE_ADDR'] == $client_ip) {
if ( WP_DEBUG_LOG ) {
@hanicker
hanicker / facebookformfill.md
Created April 21, 2019 13:20 — forked from johnnyopao/facebookformfill.md
Fill your Unbounce Forms using Facebook data

The command line, in short…

wget -k -K -E -r -l 10 -p -N -F --restrict-file-names=windows -nH http://website.com/

…and the options explained

  • -k : convert links to relative
  • -K : keep an original versions of files without the conversions made by wget
  • -E : rename html files to .html (if they don’t already have an htm(l) extension)
  • -r : recursive… of course we want to make a recursive copy
  • -l 10 : the maximum level of recursion. if you have a really big website you may need to put a higher number, but 10 levels should be enough.
@hanicker
hanicker / cloudflare-flexible-ssl-redirect-loop-fix.php
Created December 16, 2018 12:31
Simple mu-plugin (move to wp-content/mu-plugins/cloudflare-flexible-ssl-redirect-loop-fix.php) to fix cloudflare redirect and optionally force https
<?php
// Fix https detection
if( (isset($_SERVER['HTTP_CF_VISITOR']) && (strpos($_SERVER['HTTP_CF_VISITOR'], 'https') !== false)) || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)) ){
$_SERVER['HTTPS'] = 'on';
}
// Also force https (optional)
if(empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off"){
$redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];