Skip to content

Instantly share code, notes, and snippets.

View alexstandiford's full-sized avatar

Alex Standiford alexstandiford

View GitHub Profile
@alexstandiford
alexstandiford / make-wider.js
Created December 18, 2018 21:49
Bookmarklet to make the Gutenberg editor wider
javascript:(function(){
style = document.createElement('style');
style.classList.add('outline-everything-with-red');
style.appendChild(document.createTextNode('@media screen and ( min-width: 768px ) {
.edit-post-visual-editor .editor-post-title,
.edit-post-visual-editor .editor-block-list__block {
max-width: 1100px;
}
}
.edit-post-visual-editor .editor-block-list__block[data-align="wide"] {
@alexstandiford
alexstandiford / keep-referral-var-on-redirect.php
Last active March 6, 2019 20:54
Keep Referral Var on Redirect
<?php
/**
* Keeps the referral var when wp_redirect is used.
*/
function affwpsupport_keep_referral_var_on_wp_redirect( $location, $status ) {
if ( function_exists( 'affiliate_wp' ) ) {
// Get the referral variable being used in AffiliateWP.
$referral_var = affiliate_wp()->tracking->get_referral_var();
if ( $_GET[ $referral_var ] ) {
// Append the referral variable and value to the URL after the redirect.
@alexstandiford
alexstandiford / force-referral-var-on-wp-redirect.php
Last active March 6, 2019 20:16
Force Affiliate WP Referral var to Stick Around When wp_redirect is Used
<?php
/**
* Keeps the referral var when wp_redirect is used.
*/
function affwpsupport_keep_referral_var_on_wp_redirect( $location, $status ) {
if ( function_exists( 'affiliate_wp' ) ) {
// Get the referral variable being used in AffiliateWP.
$referral_var = affiliate_wp()->tracking->get_referral_var();
@alexstandiford
alexstandiford / database-comparison-test.php
Last active March 29, 2019 13:44
Testing script to compare proposed new method of getting non-affiliate, and affiliate users.
<?php
add_filter( 'wp_is_large_network', '__return_false' );
/**
* Calculates the time needed to run the specified function.
* @param $function string The callback to run.
* @param $args array Array of arguments to pass.
* @param int $number_of_times int The number of times this function should run.
* @return mixed
*/
@alexstandiford
alexstandiford / benchmark.php
Created April 2, 2019 13:23
Handy little snippet to get benchmark time for a function
<?php
/**
* Calculates the time needed to run the specified function.
* @param $function string The callback to run.
* @param $function_args array Array of arguments to pass.
* @param int $number_of_times int The number of times this function should run.
* @return array containing the following information for each benchmark:
* $benchmark_time float The amount of time this benchmark took to run
* $total_time float The total amount of time it has taken to run this function
@alexstandiford
alexstandiford / mockup-css.css
Last active July 2, 2019 15:22
Issue 1140 Mockup Markup
#tooltip {
border-radius: 100%;
border: 1px solid;
display: inline-block;
width: 20px;
height: 20px;
position:relative;
vertical-align:-6px;
margin-left:5px;
transition:all 0.1s ease-in-out;
@alexstandiford
alexstandiford / gist:0728ba7b21caa323a5ecf67c6e98abd2
Created July 24, 2019 19:33
Setup openssh server on Local Flywheel Container
#!/usr/bin/env bash
apt-get update && apt-get install -y openssh-server
sed -i "/service mysql start/aservice ssh start" /etc/scripts/startup.sh
echo "root:root" | chpasswd
sed -i "s/PermitRootLogin without-password/PermitRootLogin yes/" /etc/ssh/sshd_config
echo "ssh update complete. You may now restart Local"
@alexstandiford
alexstandiford / install-wp-tests.sh
Created August 2, 2019 15:51
Script to set up a WordPress test environment for add-ons that requires other plugins as dependencies.
#!/usr/bin/env bash
# ===================================================================================================
# Script to set up a WordPress test environment for add-ons that requires other plugins as dependencies.
# Note that this uses Composer to install the dependencies, so each dependent plugin must have Composer
# Configured properly in-order for this tool to install the dependencies properly.
#
# Ultimately, this is a modified version of the default shell script that is obtained with wp-cli's
# wp scaffold plugin-tests command. It has been updated to include steps that will install composer
# dependencies inside of the test environment's plugin directory.
@alexstandiford
alexstandiford / inactive-affiliate-404-redirect.php
Created January 3, 2020 17:54
Redirects any URL that refers an inactive affiliate to the 404 page.
<?php
/*
* Any URL that refers an inactive affiliate will be redirected to the 404 page.
*
* @since 1.0.0
*/
add_action( 'template_redirect', function() {
global $wp_query;
// Return early if not using AffiliateWP.
/**
* Webpack Config.
*
* This configuration is a fork of the config that comes with the block editor scripts.
*/
/**
* External dependencies
*/
const { BundleAnalyzerPlugin } = require( 'webpack-bundle-analyzer' );