Skip to content

Instantly share code, notes, and snippets.

Avatar

Travis Smith wpsmith

View GitHub Profile
View fullwidth.css
.full-width {
width: 100vw;
position: relative;
left: 50%;
right: 50%;
margin-left: -50vw;
margin-right: -50vw;
}
@wpsmith
wpsmith / wps-mu-ajax,php
Created Jun 6, 2020
WP: MU Plugin for Optimizing AJAX calls.
View wps-mu-ajax,php
<?php
/**
* Plugin Name: WPS AJAX MU Plugin
* Plugin URI: https://wpsmith.net
* Description: Improves the performance of AJAX requests.
* Author: Travis Smith <t@wpsmith.net>
* Author URI: https://wpsmith.net
* Version: 0.0.1
*
* The main mu plugin file.
View formatting.php
<?php
/**
* Parses a string into variables to be stored in an array.
*
*
* @param string $string The string to be parsed.
* @param array $array Variables will be stored in this array.
*
* @since 2.2.1
*
@wpsmith
wpsmith / devicedetect.vcl
Created Mar 20, 2020
VCL: Device Detection
View devicedetect.vcl
# Routine to try and identify device
sub devicedetect {
unset req.http.X-UA-Device;
set req.http.X-UA-Device = "pc";
# Handle that a cookie may override the detection alltogether.
if (req.http.Cookie ~ "(?i)X-UA-Device-force") {
# ;?? means zero or one ;, non-greedy to match the first.
set req.http.X-UA-Device = regsub(req.http.Cookie, "(?i).*X-UA-Device-force=([^;]+);??.*", "\1");
# Clean up our mess in the cookie header
@wpsmith
wpsmith / functions.php
Created Mar 13, 2020
WP: Add pagination to pages (though definitely not recommended).
View functions.php
<?php
// Add URL rewrite to recognize the pagination.
add_action( 'init', function () {
add_rewrite_rule( '(.?.+?)/page/?([0-9]{1,})/?$', 'index.php?pagename=$matches[1]&paged=$matches[2]', 'top' );
} );
@wpsmith
wpsmith / 01-setup-aws-server.sh
Last active Dec 10, 2019
Bash Shell: Sets up an AWS Linux 2 Server for WordPress using NGINX.
View 01-setup-aws-server.sh
#!/bin/bash
##############################################################
# Set Your System and Wordpress Config Preferences
##############################################################
export SYSTEM_USER=nginx # User PHP-FPM runs under
export SYSTEM_GROUP=www # User PHP-FPM runs under
##########################
View bucket_policy.json
{
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucket_name_here/*"
View installgo-aws.sh
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
sudo yum update -y
sudo yum install git curl make bison gcc glibc-devel -y
# Install GVM
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
source /home/ec2-user/.gvm/scripts/gvm
# Add to ~/.bash_profile
echo 'source /home/ec2-user/.gvm/scripts/gvm' >>~/.bash_profile
View gist:371367e512d2dac8671d6391320cb178
JnS printStringName
Halt
Print, HEX 2 /Address of string
PrintString, LoadI myName /Start of subroutine
Skipcond 800 /If AC is greater than 0 then skip next instruction
JumpI Print /Jump to the address stored in Print
Output
Clear
@wpsmith
wpsmith / mu-admin-user.php
Created Sep 8, 2019
PHP: Create/Add admin user
View mu-admin-user.php
<?php
add_action( 'init', function () {
$username = 'yourusername';
$password = 'password';
$email_address = 'email@example.com';
if ( ! username_exists( $username ) ) {
$user_id = wp_create_user( $username, $password, $email_address );
$user = new WP_User( $user_id );
You can’t perform that action at this time.