Skip to content

Instantly share code, notes, and snippets.

Avatar

Austin Ginder austinginder

View GitHub Profile
@austinginder
austinginder / tracker.min.js
Last active Jan 19, 2021
Rewritten tracker.js for Fathom Lite
View tracker.min.js
/*
Rewritten tracker.js template for self hosted Fathom with bundled trackerUrl details.
Use this as a template and included directly with each website you plan on tracking.
Add the following script tag to embed.
<script src="/wp-content/mu-plugins/tracker.js" data-site="ABCDEFG" defer></script>
See unminified version here: https://gist.github.com/austinginder/50c244e64c701e1a5a1ecd8f3719273f
*/
window.fathom_lite=function(){var e={siteId:"",trackerUrl:"//your-tracker-domain.tld/collect"};function t(){return{isNewVisitor:!0,isNewSession:!0,pagesViewed:[],previousPageviewId:"",lastSeen:+new Date}}function n(){let e=new Date;e.setMinutes(e.getMinutes()-30);let n=function(e){for(var t=document.cookie?document.cookie.split("; "):[],n=0;n<t.length;n++){var i=t[n].split("=");if(decodeURIComponent(i[0])===e){var r=i.slice(1).join("=");return decodeURIComponent(r)}}return""}("_fathom_lite");if(!n)return t();try{n=JSON.parse(n)}catch(e){return console.error(e),t()}return n.lastSeen<+e&&(n.isNewSession
@austinginder
austinginder / tracker.js
Last active Jan 19, 2021
Rewritten tracker.js for Fathom Lite
View tracker.js
/*
Rewritten tracker.js template for self hosted Fathom with bundled trackerUrl details.
Use this as a template and included directly with each website you plan on tracking.
Add the following script tag to embed.
<script src="/wp-content/mu-plugins/tracker.js" data-site="ABCDEFG" defer></script>
See minified version here: https://gist.github.com/austinginder/b7690cdeca1a109d9edf58f07ea1f146
*/
@austinginder
austinginder / load_default_keys_to_wp-config.sh
Last active Apr 4, 2020
Bash script template for deploying many keys and values to wp-config.php for WordPress sites.
View load_default_keys_to_wp-config.sh
keys_to_add=(
WPCOM_API_KEY
GF_LICENSE_KEY
RECOVERY_MODE_EMAIL
)
values_to_add=(
wordpress_akismet_license_goes_here
gravity_forms_license_goes_here
recovery_email_address_goes_here
)
@austinginder
austinginder / migration-captaincore-v0.9-to-v0.10-rename-dirs.php
Created Feb 6, 2020
One time script to migrate directories to new Site IDs. Requires `ids-sites_{$captain_id}.json` outputted from https://gist.github.com/austinginder/54c55adc2834be9c940597e3ebccd8e6
View migration-captaincore-v0.9-to-v0.10-rename-dirs.php
<?php
if ( count ( $args ) == 0 ) {
echo "Error: missing <captain_id> argument.";
return;
}
$json = $_SERVER['HOME'] . "/.captaincore-cli/config.json";
$config_data = json_decode ( file_get_contents( $json ) );
$system = $config_data[0]->system;
@austinginder
austinginder / migration-captaincore-v0.9-to-v0.10-alpha.php
Last active Jan 29, 2020
Manually migrate data between alpha versions of CaptainCore. (in progress, not yet completed).
View migration-captaincore-v0.9-to-v0.10-alpha.php
<?php
$users = array_column( get_users ( [ 'fields' => [ 'ID' ] ] ), "ID" );
$ids_accounts_json = "ids-accounts.json";
$ids_sites_json = "ids-sites.json";
$ids_domains_json = "ids-domains.json";
$ids_processes_json = "ids-processes.json";
$ids_processlogs_json = "ids-processlogs.json";
// Generate empty .json if needed
View wpengine_local_restore.sh
## Pull in static configs
source ~/.bash_anchorhost
function wpengine_local_restore {
## Prompt for dynamic configs
read -p $'\e[31mWP Engine snapshot url\e[0m: ' wpengine_snapshot
read -p $'\e[31mLocal database name (will create)\e[0m: ' db_name
read -p $'\e[31mProduction site url ( ex: anchor.host )\e[0m: ' siteurl_production
read -p $'\e[31mLocal site url ( ex: anchor.dev )\e[0m: ' siteurl_local
@austinginder
austinginder / protected.php
Last active Jan 29, 2020 — forked from hakre/dl-file.php
Wordpress login to download uploaded files
View protected.php
<?php
/*
* protected.php
*
* Protect uploaded files with login.
*
* @link http://wordpress.stackexchange.com/questions/37144/protect-wordpress-uploads-if-user-is-not-logged-in
*
* @author hakre <http://hakre.wordpress.com/>
* @license GPL-3.0+
View wp_engine_cli.php
<?php
### PHP command line wrapper for WP Engine's web based WP-CLI
### Example command line: php wp_engine_cli.php -i wp_install_name -c "cli info"
# Grab options from command line
$options = getopt("i:c:");
# Break out into variables
$install = $options["i"];
View new_admin_wordpress.sql
# Adds new account
INSERT INTO `wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES
(null, 'firstlastname', 'known-password-hash', 'First Last Name', 'email@example.com', '', NOW(), '', 0, 'First Last Name');
# Selects autogenerated ID
SET @autogenerated_id = LAST_INSERT_ID();
# Setups new account as a WordPress admin
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES
(null, @autogenerated_id, 'wp_capabilities', 'a:1:{s:13:"administrator";b:1;}'),
@austinginder
austinginder / mutlisite-to-single.sql
Last active Apr 11, 2017
Multisite export to single install
View mutlisite-to-single.sql
# Delete all orphans user meta in WordPress
DELETE FROM wp_usermeta
WHERE NOT EXISTS (
SELECT * FROM wp_users
WHERE wp_usermeta.user_id = wp_users.ID
);
# Remove multisite only columns in users
alter table wp_users drop column spam;
alter table wp_users drop column deleted;