davisshaver/railyard

There is no license information available for the latest version (1.01) of this package.

Starter kit for a Philly Publishing site.

1.01 2017-12-27 17:00 UTC

This package is not auto-updated.

Last update: 2024-04-28 02:21:58 UTC


README

This is the starter kit for new Philly Publishing Company sites. It lays out the tracks for local development and new site creation. Proprietary code and secrets can be included on a per site basis using Composer or direct commits.

Local development

Prerequisites

These tools should be installed on your local system before you begin.

  • Composer
  • PHP

Local dev workflow

New sites are ready to go from the project root. See .env.sample for keys supported in .env.

You can use Lando, Local by Flywheel, or another local dev solution.

You may want to run wp db import ./private/local/railyard.sql.gz next. This populates the database to simulate a typical Philly Publishing site. Doing this with a production database may take some time. If you are using a production database, you may need to reset a password at this point. You can do this with wp user update admin --user_pass="PASSWORD".

Tip: We ignore the file notes.md in the repository if you would like to stash commands here for use in the future.

Existing site import

Here are some tips for cleaning up existing sites.

  1. Install the Revisions command for WP CLI and then delete. See docs for more options..
wp package install trepmal/wp-revisions-cli
wp revisions clean --hard
wp db optimize
  1. Delete transients.
wp transient delete --all
  1. Delete pending comments and pingbacks.

In lieu of a WP CLI command, Sequel Pro can be used to delete pingbacks/trackbacks manually.

  1. Profile largest tables.
wp db size --tables

For your prefix (usually wp_), we need to keep the following tables:

  • wp_commentmeta
  • wp_comments
  • wp_links
  • wp_options
  • wp_postmeta
  • wp_posts
  • wp_term_relationships
  • wp_term_taxonomy
  • wp_termmeta
  • wp_terms
  • wp_usermeta
  • wp_users

Keep an eye out for extra tables, you may be able to delete them.

  1. Transferring files to S3.

Before you begin, you'll need the following:

  • S3 Bucket
  • IAM user key/secret w/ S3 full permissions on bucket
  • AWS CLI on server

On third-party servers we want to be extremely cautious of leaving the environment undisturbed.

You can short-circuit the profile configured to AWS by exporting your own key/secret to the environment:

export AWS_ACCESS_KEY_ID="REDACTED"
export AWS_SECRET_ACCESS_KEY="REDACTED"
export AWS_DEFAULT_REGION="us-east-1"

Now if you run aws s3 ls you should see the S3 bucket listed.

Assuming a standard WordPress installation, running this command from the app root will begin a sync process to your bucket:

aws s3 sync ./wp-content/uploads/ s3://onwardstate-uploads/uploads/

Now we can unset our environment variables. It's like we were never even here!

unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
unset AWS_DEFAULT_REGION

If you have setup and activated S3 Uploads, image files should load at this point. You may also want to sync all or part of S3 bucket to your server for redundancy.

For local development, S3 Uploads suggests the following:

While it's possible to use S3 Uploads for local development (this is actually a nice way to not have to sync all uploads from production to development), if you want to develop offline you have a couple of options.

  1. Just disable the S3 Uploads plugin in your development environment.
  2. Define the S3_UPLOADS_USE_LOCAL constant with the plugin active.

Option 2 will allow you to run the S3 Uploads plugin for production parity purposes, it will essentially mock Amazon S3 with a local stream wrapper and actually store the uploads in your WP Upload Dir /s3/.

At this point, you may still have an unnecessarily large uploads folder. Here are some strategies for reducing the size.

Using Node S3 Utils, we can list the uploads that have the mark of being auto-generated by WordPress. Specifically containing the last bit of ####x####.jpg.

s3utils files delete -c ./.s3-credentials.json -p uploads/ -r 'uploads\/[0-9]{4}\/[0-9]{1,2}\/(.*-[0-9]{1,4}x[0-9]{1,4}.(png|gif|jpg))'

However this function would need to be run repeatedly for the images to be cleared.

You may also want to double check that all posts have a featured image. The featured image features was introduced in version 2.9 (December 18th, 2009). Install Run Command's Assign Featured Image package and then preview & run as follows:

wp --url=onwardstate.com assign-featured-images --dry-run --only-missing
wp --url=onwardstate.com assign-featured-images --only-missing
  1. Removing subscribers.

We can use WP CLI to lookup subscribers and delete subscribers without posts.

wp user delete $(wp db query "SELECT ID FROM os08_users WHERE ID NOT IN ( SELECT DISTINCT post_author FROM os08_posts ) AND ID NOT IN (4)" --url=onwardstate.com | tail -n +2 ) --url=onwardstate.com --reassign=1

The 4 here is the admin ID, which can be obtained with somthing like wp user list --role=administrator --field=ID. Comma separate multiple administrator ID's to ignore.

Theme

Terminal is the required theme for Philly Publishing publishers.