Skip to content

Instantly share code, notes, and snippets.

View twfahey1's full-sized avatar

Tyler Fahey twfahey1

View GitHub Profile
@twfahey1
twfahey1 / wp-config.php
Created January 17, 2020 15:53
Enforce https only for certain URLs in Wordpress wp-config
$urls_that_should_be_http = [
'/zonedata/manifest.txt',
'/zonedata/tzone_npanxx.unl',
'/zonedata/new_tzones.full.unl',
'/zonedata/tzone_tollfree.unl',
'/zonedata/tzrules.unl',
'/hello-world/',
];
@twfahey1
twfahey1 / settings.php
Last active February 7, 2020 01:17
Override Pressflow settings for Drupal 7 on Pantheon, override temporary file path, database, add a prefix, and more.
<?php
/**
* On Pantheon, the way Pressflow settings are injected in Drupal 7, it becomes impossible to
* override the temp directory, as well as some other settings. The workaround demonstrated here
* should allow for overriding Pressflow settings on Pantheon.
*/
if (isset($_ENV['PANTHEON_ENVIRONMENT'])) {
// Pressflow will override whatever we set here unless we override Pressflow first.
@twfahey1
twfahey1 / some_module.install
Created February 5, 2020 18:53
Install hook to update database with entity definitions - Drupal 8
<?php
/**
* Update 8001 - Create foobar entity.
*/
function aws_bucket_fs_update_8001() {
//check if the table exists first. If not, then create the entity.
if(!db_table_exists('foobar')) {
\Drupal::entityTypeManager()->clearCachedDefinitions();
\Drupal::entityDefinitionUpdateManager()
@twfahey1
twfahey1 / run.sh
Created February 12, 2020 22:04
Create a WP User with admin privileges (similar to drush uli)
wp user create tyler [email protected] --role=administrator
@twfahey1
twfahey1 / watch-backups.sh
Last active April 23, 2020 21:17
Run a backup with terminus, and check on the progress, for long running backups on Pantheon
#!/bin/bash
# Run this as ./watch-backup <site>.<env>, for the site & env to use.
do_backup() {
terminus backup:create $1 > /dev/null 2>&1
}
get_latest_backup_url() {
str=$(terminus backup:info $1 --field=URL)
@twfahey1
twfahey1 / settings.php
Created April 24, 2020 16:59
Block IP addresses in PHP
<?php
$deny = array("111.111.111", "222.222.222", "333.333.333");
if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
header("location: https://example.com/");
exit();
}
?>
@twfahey1
twfahey1 / run-command.sh
Created May 13, 2020 15:59
Run php script with drush against Pantheon site with terminus
➜ echo "print_r( variable_get('mail_system'));" | terminus drush my-pantheon-site.dev -- php-script -
Array
(
[default-system] => DefaultMailSystem
[htmlmail] => HTMLMailSystem
)
[notice] Command: my-pantheon-site.dev -- drush php-script [Exit: 0]
@twfahey1
twfahey1 / DropzoneJs.php
Created June 1, 2020 14:58
DropzoneJs fix for Pantheon multiple appserver environments
<?php
namespace Drupal\dropzonejs\Element;
use Drupal\Component\Utility\Bytes;
use Drupal\Component\Utility\Environment;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element\FormElement;
@twfahey1
twfahey1 / gist:1feba46ea46741a270de4709ab2155fd
Created July 16, 2020 14:41
Show tables with engine and size - MySQL
SELECT table_name AS "Tables", engine AS "Engine",
-> round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB"
-> FROM information_schema.TABLES
-> WHERE table_schema = "pantheon"
-> ORDER BY (data_length + index_length) DESC;
@twfahey1
twfahey1 / example-wp.sh
Last active August 4, 2022 11:04
Pantheon - run php-script (php eval alternative) via terminus against a site
cat hello.php | terminus remote:wp ${SITE}.${ENV} -- eval-file -