Skip to content

Instantly share code, notes, and snippets.

@wpsmith
wpsmith / devicedetect.vcl
Created March 20, 2020 15:14
VCL: Device Detection
# 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 March 13, 2020 20:40
WP: Add pagination to pages (though definitely not recommended).
<?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 December 10, 2019 23:23
Bash Shell: Sets up an AWS Linux 2 Server for WordPress using NGINX.
#!/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
##########################
{
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucket_name_here/*"
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
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 September 8, 2019 02:15
PHP: Create/Add admin user
<?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 );
@wpsmith
wpsmith / s3Upload.sh
Created June 18, 2019 18:54
SH: Uploads file to IBM Cloud Object Storage (US Standard)
#!/usr/bin/env bash
# Set AWS credentials and S3 paramters
S3_KEY="YOUR_KEY_GOES_HERE"
S3_SECRET="YOUR_SECRET_GOES_HERE"
S3_BUCKET="YOUR_BUCKET_NAME_GOES_HERE"
S3_BUCKET_PATH="/"
S3_ACL="x-amz-acl:public-read"
S3_URL="https://s3.us.cloud-object-storage.appdomain.cloud/"
@wpsmith
wpsmith / is_rest.php
Last active June 4, 2019 13:48
PHP: Determines whether the request is a WordPress API request.
<?php
/**
* Determines whether the current request is a RESTful request.
*
* @return bool
*/
function is_rest() {
return (
( defined( 'REST_REQUEST' ) && REST_REQUEST ) ||
@wpsmith
wpsmith / composer.json
Created May 5, 2019 00:22
CMB Autoloading with Composer
{
"require": {
"php": ">=5.3.0",
"composer/installers": "v1.0.12",
"webdevstudios/cmb2": "dev-master"
},
"autoload": {
"files": ["vendor/cmb2/init.php"]
},
"extra": {