Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Download and install on your Pantheon Wordpress site.
#!/usr/bin/env php
* This script will download and install
* on your Pantheon Wordpress site.
* Works on Macintosh / Linux.
* Usage:
* terminus auth login
* php add-php-sessions-plugin.php my-site-name [env]
while (count($argv) > 0) {
$arg = array_shift($argv);
if ($arg[0] == '-') {
switch ($arg) {
case "--port":
$sftp_port = array_shift($argv);
case "--pantheon-sessions-version":
$pantheon_sessions_version = array_shift($argv);
else {
if ($site == "") {
$site = $arg;
else {
// Generally, you should only use 'dev' or a multi-dev branch here.
$env = $arg;
function tempdir($dir=FALSE, $prefix='') {
$tempfile=tempnam($dir ? $dir : sys_get_temp_dir(), $prefix);
if (file_exists($tempfile)) { unlink($tempfile); }
if (is_dir($tempfile)) { return $tempfile; }
if (empty($site)) {
print "Usage: $self SITE [ENV]";
// Get the site UUID
$uuid = exec("terminus site info --site=$site --field=id");
// Write the wp-native-php-sessions code to the site with
// the sftp command line tool, and commit it with terminus.
// Make sure the site is awake
exec("terminus site wake --site=$site --env=dev");
$mu_plugins_path = 'wp-content/mu-plugins';
$work_dir = tempdir();
// We are going to write the pantheon sessions loader into wp-content/mu-plugins
$pantheon_sessions_loader = "<?php
require_once(__DIR__ . '/wp-native-php-sessions/pantheon-sessions.php');";
file_put_contents('00-pantheon-sessions.php', $pantheon_sessions_loader);
// Download the pantheon-sessions plugin; we are going to write it to wp-content/mu-plugins as well
exec("curl -OL$");
rename("$", "");
rename("wp-native-php-sessions-$pantheon_sessions_version", 'wp-native-php-sessions');
// Make a batch file for the sftp tool
$sftp_batch_contents = "cd code/wp-content/mu-plugins
put 00-pantheon-sessions.php
put -r wp-native-php-sessions";
file_put_contents($sftp_batch_file, $sftp_batch_contents);
// We need to be in sftp mode to write the file
passthru("terminus site set-connection-mode --site=\"$site\" --env=\"$env\" --mode=sftp");
// Use the sftp cli tool to upload 00-pantheon-sessions.php and wp-native-php-sessions
passthru("sftp -o Port=\"$sftp_port\" -b \"$sftp_batch_file\" \"$sftp_host\"");
// Commit it to the database.
passthru("terminus site code commit --site=\"$site\" --env=\"$env\" --message=\"Add wp-native-php-sessions/pantheon-sessions to the must-use plugins directory.\" --yes");

This comment has been minimized.

Copy link

commented Apr 4, 2016

Hi Greg,

Could you please verify the terminus command in line 105? It seems to have been changed to terminus site set-connection-mode with a --mode parameter based on this page and we have one report of an error on that command. Thanks!


This comment has been minimized.

Copy link
Owner Author

commented Apr 11, 2016

You are correct -- I updated the gist. I have not tried the whole script in context recently, though.


This comment has been minimized.

Copy link

commented Jul 28, 2016

Hi Greg

I forked and made some changes in order to switch wget to curl (installed pr default for mac users) and to reflect the latest version of the plugin.

Could you review here:


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.