Skip to content

Instantly share code, notes, and snippets.

View carl-alberto's full-sized avatar

Carl Alberto carl-alberto

View GitHub Profile
@carl-alberto
carl-alberto / listdomains.sh
Created October 9, 2021 11:52
Terminus list all domains in an org
#!/bin/bash
# usage sh listdomains.sh ORGUUID
# Exit on error
set -e
# Stash org UUID
#ORG_UUID="99da9da0-46f1-4346-8bef-03325d645b5c"
VARNAME=$1
@carl-alberto
carl-alberto / gist:69ea85616f1f6510f06633ad9f491e96
Created February 6, 2021 05:05
Enabling extensive debugging in dev & multidev env in Pantheon
if (defined('PANTHEON_ENVIRONMENT')) {
// Turns on WordPress debug settings in development and multidev environments, and disables in test and live.
if (!in_array(PANTHEON_ENVIRONMENT, array('test', 'live'))) {
// Debugging enabled.
if (!defined('WP_DEBUG')) {
ini_set( 'log_errors','On' );
ini_set( 'display_errors','On' );
ini_set( 'error_reporting', E_ALL );
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
@carl-alberto
carl-alberto / gist:93cd944098f5acfc75ba134f7962d650
Created January 22, 2021 10:54
pagespeed detection script
<?php
function bot_detected() {
$u_agent = $_SERVER['HTTP_USER_AGENT'];
if(strlen(strstr($u_agent,"Lighthouse")) > 0 ){
return false;
} elseif(strlen(strstr($u_agent,"GTmetrix")) > 0 ){
return false;
@carl-alberto
carl-alberto / gist:d2e3ba70101e4ea76cb4d20e5d96d382
Created October 13, 2020 02:38
sample WordPress dequeue with certain user-agent is detected
function bot_detected() {
$u_agent = $_SERVER['HTTP_USER_AGENT'];
if(strlen(strstr($u_agent,"Lighthouse")) > 0 ){
return false;
} else {
return true;
}
}
add_action( 'init', 'my_deregister_init', 9999999999999999 );
function additional_securityheaders( $headers ) {
if ( ! is_admin() ) {
$headers['Access-Control-Allow-Origin'] = '*';
}
return $headers;
}
add_filter( 'wp_headers', 'additional_securityheaders' );
<?php
/*
Plugin Name: WPCFM Helper
Plugin URI: https://pantheon.io
Description: Helper for WP CFM
Version: 0.1
Author: Pantheon / Carl Alberto
Author URI: https://carlalberto.code.blog
*/
@carl-alberto
carl-alberto / gist:6feacbe77426ae63ad4909be72035690
Last active June 13, 2020 23:38
Block IP via php in wp-config.php
if ( !file_exists('blocked_ips.txt') ) {
$deny_ips = array(
'127.0.0.1',
);
} else {
$deny_ips = file('blocked_ips.txt');
}
// read user ip adress:
$ip = isset($_SERVER['REMOTE_ADDR']) ? trim($_SERVER['REMOTE_ADDR']) : '';
$blockAgents = array('AhrefsBot','AspiegelBot', 'MJ12bot');
foreach ($blockAgents as $agent) {
if (strpos($_SERVER['HTTP_USER_AGENT'], $agent) !== FALSE) {
exit();
}
}
<?php
// Replace badcookiename with the cookie that you are trying to override
// Add in a custom plugin or theme's functions.php
add_action(
'init',
function() {
if ( isset( $COOKIE['wp-goodcookiename'] ) ) {
$COOKIE['badcookiename'] = $COOKIE['wp-goodcookiename'];
@carl-alberto
carl-alberto / .htaccess
Created April 22, 2020 09:49
Disable XML RPC in WP
# Block WordPress xmlrpc.php requests
<Files xmlrpc.php>
order deny,allow
deny from all
allow from 123.123.123.123
</Files>