Skip to content

Instantly share code, notes, and snippets.

@lewayotte
lewayotte / keybase.md
Created September 23, 2014 12:40
Keybase proof

Keybase proof

I hereby claim:

  • I am lewayotte on github.
  • I am lewayotte (https://keybase.io/lewayotte) on keybase.
  • I have a public key whose fingerprint is 85F8 1C87 8605 30B0 22CE EF00 CCCF 4C72 9FE6 D1C1

To claim this, I am signing this object:

@lewayotte
lewayotte / cloudflare-dns.php
Last active March 17, 2022 09:32
Cloud Flare Automatic DNS Record Updater (PHP Script)
#!/usr/bin/php
<?php
/**
* Script used to update DNS records in Cloud Flare when server IP address changes.
* My use case is to run this script on startup, when I spin up a new Digital Ocean VPS but
* this could easily be used to update for dynamic DNS with a cronjob.
*
* Digital Ocean referral code: https://www.digitalocean.com/?refcode=3655e259ce29
*
* Requires PHP cURL
@lewayotte
lewayotte / alphanumeric_increment.php
Created December 16, 2014 15:04
Incrementing alphanumeric strings in PHP
function alphanumeric_increment( $string, $position=false ) {
if ( false === $position ) {
$position = strlen( $string ) - 1;
}
$increment_str = substr( $string, $position, 1 );
switch ( $increment_str ) {
case '9':
$string = substr_replace( $string, 'a', $position, 1 );
break;
case 'z':
@lewayotte
lewayotte / secret_user_login.php
Last active July 24, 2017 23:44
mu-plugin to log in as any WordPress user without a known password
<?php
/*
* **** WARNING: THIS IS VERY INSECURE - DELETE AFTER USE ****
*
* This will let you log in as any WordPress user if you know their user ID. This is for support only!
*
* Stick this file in the wp-content/mu-plugins directory
* Browse to http://domain.tld/?user_id=USER_ID
* You'll be logged in as that user!
*
@lewayotte
lewayotte / paypal-payment-url.php
Created March 24, 2015 15:29
PayPal Payments - WordCamp ATL 2015
<?php
if ( !defined( 'PAYPAL_PAYMENT_LIVE_URL' ) )
define( 'PAYPAL_PAYMENT_LIVE_URL', 'https://www.paypal.com/cgi-bin/webscr' );
if ( !defined( 'PAYPAL_PAYMENT_SANDBOX_URL' ) )
define( 'PAYPAL_PAYMENT_SANDBOX_URL', 'https://www.sandbox.paypal.com/cgi-bin/webscr' );
/* Insecure */
function insecure_paypal_payment_url() {
$paypal_email = 'you@domain.tld';
@lewayotte
lewayotte / stripe-payment-button.php
Last active July 24, 2017 23:44
Stripe Payments - WordCamp ATL 2015
<?php
// Custom forms: https://stripe.com/docs/tutorials/forms
function stripe_payment_button() {
$payment_image = false;
$publishable_key = 'key';
$transaction_return_page = get_permalink( 1 ); //Whatever page ID you're using for your transaction return page
$description = 'S-Mart';
@lewayotte
lewayotte / restricted-content.php
Created March 25, 2015 19:53
Restricted Content in WordPress - WordCamp ATL 2015
<?php
function restricted_content_filter( $content ) {
if ( !current_user_can( 'administrator' ) && is_content_restricted() ) {
$content = 'Restricted!';
}
return $content;
}
add_filter( 'the_content', 'restricted_content_filter' );
add_filter( 'the_excerpt', 'restricted_content_filter' );
@lewayotte
lewayotte / natgeomapsscraper.pl
Created October 20, 2015 03:59
PERL script used to scrape all the Nat Geo Trail Map images. Use Photoshop or GIMP later to piece the images together for a good digital copy.
#!/usr/bin/perl
# June 13, 2011
# Lew Ayotte
use strict;
use Getopt::Long;
use File::Path;
# GLOBAL VARIABLES #
my $ASSETS_BASE_URL = 'http://www.natgeomaps.com/assets/files/zoomify/';
@lewayotte
lewayotte / revision-reverter.php
Created January 7, 2016 13:16
Automatically remove all revisions with a "bad" word and revert to the last revision without the bad word - used for cleaning up spam injected content.
<?php
function post_revision_menu_page() {
add_menu_page( 'Revisions', 'Revisions', 'manage_options', 'revision', 'post_revision_page' );
}
//add_action( 'admin_menu', 'post_revision_menu_page' );
function post_revision_page() {
/*
//Time Check
@lewayotte
lewayotte / wprobot-leenkme.php
Last active January 12, 2016 14:46
Delay WP Robot posts by 3 minutes for leenk.me's use
<?php
function setup_wprobot_filters_for_leenkme( $content, $title, $catarray ) {
add_filter( 'wp_insert_post_data', 'delay_wp_robot_posts_by_3_minutes_for_leenkme', 10, 2 );
}
add_action( 'wpr_before_post_save', 'setup_wprobot_filters_for_leenkme', 10, 3 );
function delay_wp_robot_posts_by_3_minutes_for_leenkme( $data, $postarr ) {
if ( 'publish' === $data['post_status'] ) {
$data['post_status'] = 'future';