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 / plugin-filter.php
Last active May 10, 2021 05:36 — forked from carlodaniele/plugin-filter.php
A Must-use plugin to filter active plugins in on a per-page basis. selectively load plugin per page
<?php
/**
* @package active-plugins
* @version 1.0
*
* Plugin Name: Active Plugins
* Plugin URI: http://wordpress.org/extend/plugins/#
* Description: This is a development plugin
* Author: Carlo Daniele
* Version: 1.0
@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 / sendtoftp.php
Created August 27, 2015 04:58
ftp file transfer from one remote server to another
<?php
$file = 'filetosend.zip';
$remote_file = 'destinationfilename.zip';
$ftp_server = '127.0.0.1';
$ftp_user_name = 'ftp@domain.com';
$ftp_user_pass = 'ftpPASSWORD';
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
@carl-alberto
carl-alberto / gist:e896b8c281f1085a2cd5170cb2be1a2e
Created March 31, 2020 14:02
Additional security headers
/**
* Add security headers for Nginx based sites
*
* @param [type] $headers add security headers as array.
*
* @return array
*/
function additional_securityheaders( $headers ) {
if ( ! is_admin() ) {
$headers['Referrer-Policy'] = 'no-referrer-when-downgrade';
@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']) : '';