Move WordPress media uploads to a subdomain

I recently decided to move my WordPress media uploads to a subdomain to improve site speed and help keep things organized for better backups. These are the things I did and issues I ran into along the way.

I recently updated my personal homepage, and decided to collect all my writing about code from three other sites that I’d worked on over the years. So, I exported the Posts from each of those sites, and imported the .xml files to my new site in order to shift the Posts to my new homepage. Along the way, I decided to move my new site’s media uploads folder to a subdomain, and I ran into a few problems along the way.

Why move media to a subdomain

There are a couple of reasons for this:

  1. To speed up my site by allowing simultaneous downloads from multiple sources at once (almost acting like a mock CDN)
  2. To keep things organized and make taking site backups easier (by backing up the database and files separately)
  3. To do a “dry run” on a small site before attempting the same thing on a large site I run (400+ Posts)

How to move media to a subdomain

  1. Create the subdomain on your host files.sitename.com for example
  2. Download ALL the old media files from your WordPress /wp-content/uploads folder via FTP
  3. Upload ALL the media files to your new subdomain
  4. Change your Upload folder to the subdomain in your WordPress settings

You may need to type /wp-admin/options.php in the URL bar and scroll down to upload_path and upload_url_path as this menu option is not visible in the WordPress menu.

  • upload_path : directory root for subdomain
    • set it to /home/server_root/sitename/folder
    • Echo the following from an index.php file at the site root to find your directory root path: <?php echo $_SERVER["DOCUMENT_ROOT"]; ?>
    • Mine is /home/server_root/sitename/media
  • upload_url_path : actual URL path for the subdomain
    • Mine is https://files.sitename.com/media

After changing those options, you should see them appear now in the WordPress Settings → Media menu.

  1. Change your Live Image URLs with a database Search & Replace plugin (this is easier than phpMyAdmin). Two good options are:
    1. Search & Replace by Inpsyde GmbH
    2. Better Search Replace by Delicious Brains

(I actually prefer the first one because it seems to run faster (there is no loading bar at the bottom of the screen) and also includes the option to download an SQL backup of your database from the first screen in the plugin – and then import it again if your search/replace fails or causes problems.)

  • Search: http://www.oldsitename.com/uploads
  • Replace: http://subdomain.sitename.com/media

Double check everything is working by trying to upload a new image, and checking your old Posts that had loaded the older images (open a different page or empty the page cache first).

  1. Redirect images that are already indexed by search engines. Do this by adding the following to your .htaccessfile:
RedirectMatch 301 ^/wp-content/uploads/(.*)$ http://img.yoursite.com/$1
  1. Finally, it might be a good idea to create a homepage for the subdomain that directs visitors back to your main site or allows them to search it (otherwise they’ll be met with either a blank page or a 403 Access Forbidden error). Here’s a good article that provides more details, and an example.

Problems I ran into

  1. I have a number of Galleries on my old WordPress Posts, but the way the gallery references images is not with an image URL, but with the gallery shortcode. It looks like this:
[ gallery type="rectangular" link="none" size="medium" ids="31183,31184" ]

So, actually, even when I imported my old Posts to the new site, I didn’t get any of the old galleries showing up because the media IDs which are referenced in the gallery shortcode seem to not be the same on the new site – even if I click “Download and import file attachments.”

  1. When I checked the image code on the old site, it also looked like some of what the site was serving up were some kind of “responsive images.”

One of the themes I wrote before did add support for responsive images, so it seems like those are being served up a bit differently than “normal” images. For example, the URL of some of those images included https://io.wp or something similar – as if being loaded through a default WordPress CDN.

  1. Even after updating and changing everything, the images on my subdomain did not show up inside my Media Library.

Resources

Atomic Habits that will turn you into a Superhero

Drawing on numerous resources, this presentation investigates what habits are, how they work, and how building the right ones into your life will turn you into a literal superhero. We’ll take a look at triggers, cravings, and rewards; the formation of good habits and the destruction of bad habits; and the top 6 High Performance Habits developed by Brendon Burchard and the High Performance Institute after over a decade of research and coaching.

Have you ever felt too busy? Overwhelmed? Stretched too thin? Your work doesn’t have to be like that. Your life in particular, shouldn’t be like that.

Drawing on numerous resources, this presentation investigates what habits are, how they work, and how building the right ones into your life will turn you into a literal superhero. We’ll take a look at triggers, cravings, and rewards; the formation of good habits and the destruction of bad habits; and the top 6 High Performance Habits developed by Brendon Burchard and the High Performance Institute after over a decade of research and coaching.

If you’ve ever wondered such things as “How long does it take to develop a new habit?” or “What if I fail in maintaining my habits?” or even “Which habits will move the needle the most in my professional and personal life?” then this talk is for you. The talk also ends with a discussion on good and bad teaching habits and how to improve yourself in your classroom and office.


Overview

What’s the difference between superheroes and us “normal” people?

Could it be living a life of purpose? Purpose leads to fulfillment. Fulfillment equals happiness.

Some people die at 25 and aren’t buried until 75.

Ben Franklin

A basic framework for happiness:

  • Engagement: Time spent daily, hopefully in a job that challenges us, but also in our after-hours hobbies. (see Power of Full Engagement)
  • Mastery: An ability to show ourselves that we are making consistent progress and improvements toward a specified goal. (see Drive)
  • Flow: Energy and attention dedicated each day to an activity that puts us in the zone. (see Flow)

Happiness is a consequence of the things you do daily, not a reward.

Steve Kamb, Level Up Your Life

Your (Super) Hero’s Journey

  1. Act 1
    1. Introduction to the protagonist’s world (that’s you!)
    2. Call to Action: Habits? What about Freedom?
      1. Neuro-pathways & Significance of your Identity
    3. Crossing the Threshold: How habits work
      1. Immediacy and addiction
  2. Act 2
    1. Meet the Mentor(s)
      1. Be intentional
      2. Reframe your mind
      3. Get some Accountability
    2. First Challenge: Make Good Habits inevitable
      1. The Law of Least Effort & The Goldilocks Principle
      2. Keystone habits & Habit stacking
    3. Temptation: Make Bad Habits impossible
    4. Dark Moment: 
      1. Importance of your Environment
      2. Schedule over Scope (Don’t break the Chain)
      3. Frequency: “How long”? Try “how much”?
  3. Act 3
    1. Final Conflict: High Performance (Superhero) Habits
      1. Personal: Seek Clarity
      2. Personal: Generate Energy
      3. Personal: Raise Necessity
      4. Social: Increase Productivity
      5. Social: Develop Influence
      6. Social: Demonstrate Courage
    2. Return home (changed): Systems trump Goals (“Continue playing for the love of the game”)

Ready Player One

1.1 Introduction

How’s life? 

Have you ever felt too busy? Overwhelmed? Stretched too thin? Your work doesn’t have to be like that. Your life in particular, shouldn’t be like that. 

A 2006 Duke University study indicates that more than 40% of your daily activities are habitual. Not enjoying your day? Change your habits.

We are what we repeatedly do. Excellence, then is not an act, but a habit.

Will Durant

1.2 Call To Action

Once more, from above: “Not enjoying your day? Change your habits.”

But what about Freedom?

Many people think that increasing our Habits decreases our Freedom for choice in life. But the opposite is actually true.

  • Jocko Willink (former US Navy Seal): posted a picture of himself surfing with his son before work one morning.
    • Commenter #1: “Must be nice.”
    • Commenter #2: “Discipline equals freedom.”
    • Advice: Be incredibly disciplined about parts of your day so that you have the freedom to enjoy the rest of your day.
  • Steve Jobs (& Mark Zuckerberg): often wear the same thing every day
    • Advice: Make decisions in advance, be as habitual as possible about certain things, to reduce cognitive load and allow yourself more brain power for the things that truly matter.

Introduction to “Neuro-pathways”

Neuro-pathways are connections formed in the brain between neurons in different areas of the brain. The more you perform a certain habit, the more deeply ingrained it becomes. But, we can change our neuro-pathways.

Your life moves in the direction of your strongest thoughts. Don’t like where your life is moving? Change your thoughts!

Craig Groeschel (paraphrase)

Every thought or action is a “vote” for who you are or want to become. Over time, will “Future You” thank you for the decisions “Current You” is making to shape his/her identity?

1.3 Crossing the Threshold

Charles Duhigg wrote an excellent book called The Power of Habit that clearly lays out how habits work, how to change bad habits into good ones, and how to create new habits.

How Habits work

  1. Cue: Something triggers your habit or a Craving
  2. Routine: You do something to satisfy this
  3. Reward: The cycle has a clear ending

Often, you cannot fully control the Cue nor the Reward. Therefore, Duhigg argues that to change a habit, you should focus on the Routine. In truth, all people have control over the choices they make about their habit routines. But many people feel controlled by their habits, not in control of them. 

  • Why do I do what I don’t want to do?
  • Why don’t I do what I want to do?

Additionally, many people express difficulty in creating new habits or breaking old, deeply ingrained ones.

Immediate Consequences

In the book Atomic Habits, James Clear points out that “immediate” rewards or consequences are the key. 

  • That which is immediately rewarded = repeated
  • That which is immediately punished = prevented

Returning to our discussion of “Future You” vs. “Current You,” we can understand how “Current You” is more in favor of Netflix and ice cream after a long day at work than in helping “Future You” become fit. The craving for immediate, visible gratification often outweighs our desire for long-term positive outcomes precisely because we cannot immediately perceive that our efforts have had any effect. 

  • Netflix + ice cream = immediate stress relief and relaxation
  • Exercise at the gym = muscular pain for…. what? long-term health? No thanks, I’ll take the immediate hit of sugar and comedy~

Rising Action

2.1 Meeting the Mentor(s)

Much of this next section includes notes from James Clear’s Atomic Habits. Check out his blog for more great articles.


Humans tend to be weak in the moments of Craving or HATS (Hunger, Anger, Tiredness, Stress). But there are a few things we can do about it:

  1. Release tension, Set intention (from High Performance Habits)
  2. Reframe the Cues
  3. Get some Accountability

Set intention practices

  • During the pauses between activities, mentally release what was, and decide on what you will make of what is to come.
    • After work, in front of my door, take 10 deep breaths, release my work stress, determine to smile at my wife and greet my children with hugs first upon entering the house
  • Visualize the outcome you want
    • Michael Phelps: famously played “mental videotapes” in his head every night before bed during training and before every meet in which he “performed” at his peak – when the race came, he did
    • Arnold Schwarzenegger: when interviewed after his first movie “Hercules in New York” flopped, claimed he’d “be the biggest name in Hollywood” 
  • Write out an “Implementation Intention
    • Research indicates that writing down your intention to do a certain thing at a certain time and place raises the likelihood you’ll stick with your intention to 91% (compared with 35-38% success if you rely on motivation or self-control alone)

Reframing practices

  • Your Cue can be deceptive and you can change how you interpret it
    • You don’t crave chips, you crave something sweet and crunchy
    • You don’t crave alcohol, but you are thirsty, need to relax, and want some flavor
    • You don’t crave a cigarette, you crave conversation (or alone time) outside the office in the cool fall air
    • You don’t crave sex with a stranger, you crave physical release (exercise) or human contact (snuggling)
    • Your heart rate and breathing increasing, palms getting sweaty before a competition or presentation isn’t you being afraid of that, it’s your body preparing you to perform at the highest level

Accountability practices

  • Find someone who’s already doing what you want, and ask to join them (training at the gym)
  • Sign a “Habit Contract” with a partner that lays out immediate consequences (like giving a set amount of money to something or someone you hate) if you fail to live up to your end of the bargain

2.2 First Challenge

Time to put what you’ve learned about Habits to work. Let’s create a NEW one! Advise: start small. The “Path of Least Resistance” teaches us that the easiest thing to do is the thing you will do. So, setting a goal of ONE pull-up per day is a much easier (and better) way to get started exercising than trying to begin going to the gym everyday. 

(Note: I literally remade my life in 2013 in a similar fashion after I first listened to The Power of Habit.) 

Make Good Habits inevitable

  1. Cue: Make it obvious
    1. An alarm, a time of day, after a certain activity, in a certain place
    2. You can also pair a new habit with a Keystone habit (one that is the “gateway” to other habits), or Stack your habits
  2. Craving: Make it attractive
    1. Temptation bundling = give yourself something you want (chocolate) for doing something you need to do (exercise)
  3. Routine: Make it easy
    1. Use the “Path of Least Resistance” to determine the smallest step you need to take to begin a new habit. 
      1. Want to run? Set out your clothes the night before.
      2. Read more? Set a book on your bed after you make it.
      3. Wake up early? Get home by 10pm.
    2. Additionally, the “Goldilocks Rule” says that if something is too easy or too hard, you won’t stay motivated. Things within 4% of a “stretch” are “just right” and allow us to continually progress.
  4. Reward: Make it satisfying
    1. Satisfy your Craving – eat the chocolate, watch the Netflix show, drink your special coffee, etc

Here’s a practical example of something I should start doing a better job of.

My example: Grading student work:

  1. Cue: Every Friday at 3pm
  2. Craving: need a mid-afternoon energy boost
  3. Routine: sit down at the computer, open the Gradebook on the left and assignments on the right, begin grading
  4. Reward: buy a latte (I don’t buy them often), or eat my favorite chocolate

Keystone habits & Habit Stacking

  • Keystone habits are habits that set the foundation for and naturally lead in to other habits
    • Good ones:
      • I wake up early so
      • I eat breakfast and go to the gym so
      • I shower so
      • I shave so
      • I brush my teeth so
      • I feel healthy so
      • I’m energized so
      • I arrive at work energized so
      • I do my best work so
      • I get promoted…
    • Bad ones:
      • I wake up late so
      • I’m rushed so
      • I don’t eat breakfast so
      • I’m angry on the road to work so
      • I get in an accident so
      • I arrive late so
      • I snap at my coworkers so
      • I under-perform so
      • I get fired… 
  • Habit stacking is where you look through your current habits and determine a place (with a Cue that is the completion of one habit) where you can insert a new habit
    • For example, in the “Good” list above, how about inserting “read for 15 minutes” after “I brush my teeth”? Then, you list will read:
      • … I brush my teeth so
      • <I read for 15 minutes so>
      • I feel healthy <and smart> so

2.3 Temptation

Reverse the habit loop above to flip bad habits upside down and destroy them!

Make Bad Habits impossible

  1. Cue: Make it invisible
    1. Put the TV in the closet, keep your phone in another room, keep junk food out of the house, drive down a different road at lunch
  2. Craving: Make it ugly
    1. Picture yourself with 20 extra kg, visualize the fat and calories seeping into your blood stream and clogging your arteries, enable black & white mode on your phone
  3. Routine: Make it difficult
    1. Remove batteries from the remote, delete the app altogether, change your environment (more on this in the next section)
  4. Reward: Make it empty
    1. Chide yourself whenever you engage in that behavior, remove one good thing you enjoy from your life as a consequence, pay the dues of your “Habit Contract” (above)

My example: Checking Facebook:

  1. Cue: I’m bored, need entertained, or want some connection
  2. Craving: I visualize it as a slot machine that delivers politically-charged negativity more than it delivers real satisfaction
  3. Routine: Deleted the Facebook app in June
  4. Reward: (also with YouTube) I only give it one page scroll when I’m in a “bored” state of mind

2.4 Dark Moment

But what if you fail? Obviously we cannot succeed 100% of the time.

When you FAIL at Good Habits

  •  Never Miss Twice: Get back on the horse as quickly as possible. Anyone (everyone) can have a bad day. It’s not a single mistake that changes the direction of your life. But a series of many missteps over many years, a repeated pattern of “bad” behavior will. Correct yourself as quickly as possible and get back at it.
  • Don’t Break the Chain: Use a calendar and put a green circle around any day you perform your good habit. After a while, you will start a series of green circles (indicating success), and you will find yourself mentally looking for ways to NOT break your cycle.

When you FAIL at controlling Bad Habits

  • Environment: Understand that your environment has a HUGE impact on your habits
    • In the Vietnam War, up to 20% of soldiers became addicted to heroin (35% reported having tried it). After returning home (to a new environment), only 5% of them were re-addicted in one year (12% in three years)
    • The opposite statistics are often true for domestic heroin addicts who go to rehab, get clean, and then return to the same old environment that led to their addiction
    • Upgrade your Bat Cave (from Level Up Your Life): If your environment is causing you to stumble, change it! You have control over the many of the things you see, listen to, do, and eat every day.
  • Identity: Remind yourself of who you ARE deep down (like Simba in the Lion King). Are you really the kind of person who does these things? No! Remind yourself who you ARE and that each vote (action) FOR or AGAINST that identity will make it stronger or weaker.

Anecdote on Identity:

There was a young boy who loved to play baseball. He would go out to the field all the time, throw the ball up in the air, and try to hit it.

  1. On the first throw, he said, “Here comes Johnny, the greatest hitter who has ever lived!” He threw it up. A swing, and a miss.
  2. On the second throw, “I’m still the greatest hitter who has ever lived!” A throw, a swing, and a miss.
  3. On the third throw, “I’m still the greatest hitter who has ever lived!” Again, throw, swing, miss.
  4. Finally, he exclaimed: “WOW! I can’t believe it! I’m also the greatest pitcher who has ever lived! Because I just struck out the greatest hitter who has ever lived!”

Climax

The habits outlined in this next section come from Brendon Burchard’s High Performance Habits. Check out his blog for more great articles.

3.1 Final Conflict

So, what are THE best habits you can cultivate in your own life? Here are notes about 6 that have been compiled by Brendon Burchard at the High Performance Institute after over a decade of hands-on research and coaching with world-class performers.

I’ve mapped these habits to many of the spokes on Dan Miller’s Wheel of Life from his book 48 Days to the Work You Love:

High Performance Habits

Personal Habits

  1. Seek Clarity (Mind)
    1. What’s your Identity? Are you who you want to be? What kinds of things would that person do / not do? Am I living into that Identity?
    2. What are your Habits? Be mindful of this. Perform a self-inventory and determine where there’s room for improvement.
    3. Set up Quarterly reviews. I’ve personally found it very helpful to quarterly take a FULL day away to brainstorm and become VERY clear about myself, my habits, environment, and vision for the future. It makes the next quarter much smoother. Two good resources:
      1. Your Best Year Ever by Michael Hyatt
      2. The 12-Week Year by Brian P. Moran & Michael Lennington 
  2. Generate Energy (Body)
    1. Physically, do you have enough energy? Exercise has been shown to help increase energy levels (as has proper nutrition)
    2. Can you bring energy to what you do? Are you passionate and alive about it?
    3. Personally: I go to the gym every morning before 7am and commute by bike. The mental and physical benefits are immeasurable.
  3. Raise Necessity (Spirit)
    1. People with a greater sense of “necessity” are more likely to follow-through with their tasks. Raise your “necessity”, raise your follow-though.
    2. How important is it that you get a certain thing done?
    3. Personally: When I find myself slacking, I have to constantly go back to my “Why” (Start with Why) to remind myself why I’m pushing and hustling and working hard.

Social Habits

  1. Increase Productivity (Career)
    1. How can you do more with less? How can you be more efficient with what you have? How can you accomplish tasks more quickly with the same level of quality?
    2. Set a Schedule, not a Deadline: The problem with deadlines is when we miss them, we feel guilty, and sometimes even give up on what we were doing – even if we’re better off now than when we started.
    3. Personally: This means getting up every single morning (even Sundays) well before the sun is up. I try to set aside a minimum of 3 hours every morning before work to accomplishing my personal (non-work related) most important tasks.
    4. Prioritize Education over Entertainment: I’ve also not had a TV for 10 years. I spend the majority of my “down” time engaged in some kind of “active” relaxation that is stimulating my brain and helping me learn new skills. Increase the output that matters and get insanely good at new skills.
  2. Develop Influence (Social)
    1. Get out there and meet people. You can’t accomplish much alone. Build a team before trying to change the world.
    2. Lead by Example: Be a leader. Stand up and role model the way. Encourage others to follow your example.
    3. Personally: I’m involved in a few organizations where, if something needs done, I just do it. This has led to others being more open about stepping up and helping out as well. 
  3. Demonstrate Courage (Legacy)
    1. Find someone to fight for. Who needs your “A game”? Play big or go home. Take bold action. Dream big dreams.
    2. Personally: After my wife gave birth to our first child (son), I had a sudden, sinking realization that my life was no longer my own, and that my base income was no longer sufficient to sustain a growing family. I raised my “A game” and courageously stepped out into every opportunity that presented itself.

3.2 Return Home (changed)

Continue playing for love of the Game (or why Systems trump Goals)

Five years ago tomorrow, Scott Adams, creator of Dilbert wrote on his blog about the difference between Goals and Systems (James Clear expands upon the failings of setting Goals without Systems):

In my new book, How to Fail at Almost Everything and Still Win Big: Kind of the Story of My Life, I talk about using systems instead of goals. For example, losing ten pounds is a goal (that most people can’t maintain), whereas learning to eat right is a system that substitutes knowledge for willpower.

Scott Adams

What’s the difference?

Systems vs. Goals

  1. Winners and losers have the same goals, but winners create superior systems to accomplish those goals
  2. Achieving a goal is momentary, but systems last a lifetime
  3. Goals actually restrict your happiness by telling you “once I reach XYZ goal, then I’ll be happy”, but systems enable happiness in the moment
  4. Goals create a “yo-yo” effect – once you pass the finish line, you stop working hard for a while until the next goal is looming, but systems enable continual, long-term, sustained effort “for love of the game

Change your game

Play the game you can win at.

  • Hicham El Guerrouj: Moroccan 2-time gold medalist and world-record holder in middle-distance running 
  • Michael Phelps: #1 most decorated Olympian in history (swimming); 7 inches taller & 40 percent heavier than Hicham

These two appear to be very different. But there is one thing they have in common: the wear the same length inseam on their pants.

But would either of them, if they switched places, under the same training and circumstances, have been the same caliber athlete as the other? Not a chance. Phelps’ body is built for swimming; Hicham’s is built for running.

Create a new game

Do you find you’re not succeeding at the game you’re playing? Create and play a new game altogether. 

A good player works hard to win the game everyone else is playing. A great player creates a new game that favors their strengths and avoids their weaknesses…

Specialization is a powerful way to overcome the “accident” of bad genetics. The more you master a specific skill, the harder it becomes for others to compete with you.

James Clear, Atomic Habits

Everyone has at least a few areas in which they could be in the top 25% with some effort. In my case, I can draw better than most people, but I’m hardly an artist. And I’m not any funnier than the average standup comedian who never makes it big, but I’m funnier than most people. The magic is that few people can draw well and write jokes. It’s the combination of the two that makes what I do so rare. And when you add in my business background, suddenly I had a topic that few cartoonists could hope to understand without living it. 

Scott Adams, creator of Dilbert

What are you skilled at? What are you fascinated by? What do you enjoy doing most that many people would argue is painful or hard to do? 

Perhaps you’ve found a new game to begin developing.


Resources

The following authors, their blogs, and books have had an enormous impact on my life. I’ve also linked to their “Academies” where applicable:

  1. Best blogs
    1. James Clear (Atomic Habits) | HabitsAcademy
    2. Steve Kamb (Level Up Your Life)| Nerd Fitness Academy 
    3. Michael Hyatt (Your Best Year Ever)
  2. Great books
    1. Brendon Burchard (High Performance Habits) | High Performance Institute
    2. Charles Duhigg (The Power of Habit)

The following collection of books are those that I’ve referenced in this talk. Each has had a significant impact on my life. Many I’ve read more than once, and some I’ve desired to read again immediately upon finishing. Be aware that these are Amazon affiliate links, so I’ll get a small commission if you click through and purchase any of them.

Welcome to WP-CLI!

I have limited experience with wp-cli but I know it’s a really quick and convenient way to manage WordPress installations. And recently I’ve been using ssh to to manage my sites more often, so I thought it would be a good time to investigate it more deeply.

I’m hosting this site on Dreamhost.com (my host since 2009), and I recently went through their One-Click install to quickly add WordPress here. But, strange thing is, I didn’t receive an email from them with my username/password combination – so I had no way to login (at first). 

After a quick Google search, I noticed that Dreamhost has a page about resetting your password – including a section on using wp-cli

I have limited experience with wp-cli but I know it’s a really quick and convenient way to manage WordPress installations. And recently I’ve been using ssh to to manage my sites more often, so I thought it would be a good time to investigate it more deeply.

Here’s a list of the very first commands I’m running on my new WP install – as well as some I intend to put to greater use in the future.

Login

First of all, we need to ssh into the server and access the site.

$ ssh username@site.com
$ cd site.com/wordpress

Change user password

$ wp user list
+----+-------------+---------------+------------------+---------------------+---------------+
| ID | user_login | display_name | user_email | user_registered | roles |
+----+-------------+---------------+------------------+---------------------+---------------+
| 1 | myusername | myusername | user@example.com | 2018-03-17 11:14:28 | administrator |
+----+-------------+---------------+------------------+---------------------+---------------+
$ wp user update 1 --user_pass=NewerBetterStrongerPassword123$
Success: Updated user 1

Create an alias to check for updates

One of the coolest things I found was that you can create an alias to run a series of wp-cli commands one after the other. The following command will check for WP core, plugin, and theme updates at once.

$ alias check-all='wp core check-update && wp plugin list --update=available && wp theme list --update-available'
$ check-all
Success: WordPress is at the latest version.
+------+--------+--------+---------+
| name | status | update | version |
+------+--------+--------+---------+
+------+--------+--------+---------+
+-----------------+----------+--------+---------+
| name | status | update | version |
+-----------------+----------+--------+---------+
| twentyfifteen | inactive | none | 2.0 |
| twentyseventeen | active | none | 1.7 |
| twentysixteen | inactive | none | 1.5 |
+-----------------+----------+--------+---------+

Update and manage core, plugins, & themes

While I could probably create another alias to update everything at once, I haven’t yet because I still like to do some things step-by-step. So, here are the three commands needed to update or manage WP core, plugins, and themes:

$ wp core update
$ wp core update --version=4.7.1

$ wp plugin update --all
$ wp plugin status
$ wp plugin install plugin-name
$ wp plugin activate plugin-name
$ wp plugin deactivate plugin-name
$ wp plugin delete plugin-name

$ wp theme update --all
$ wp theme status theme-name
$ wp theme install theme-name --activate

Many of the plugin and theme commands are quite similar and you can do certain things like stringing together some of them (wp theme install theme-name --activate).

Check your config file or databases

A couple more useful commands are to check out your wp-config file’s constants and globals, and work with your database:

$ wp config get

$ wp db size --tables
$ wp db optimize
$ wp db repair
$ wp db export filename.sql

Clean up post revisions

Sometimes you just need to clean up your post revisions, especially if your site is old or has loads of them. But first, you’ll need to install an additional wp-cli package.

$ wp package install trepmal/wp-revisions-cli
$ wp revisions clean

Or, for specific posts and/or dates:

$ wp revisions list --post_id=ID
$ wp revisions clean --post_id=ID --before-date="YYYY-MM-DD"

Remove all spam comments

This one looks to be a great help, especially for big installations that get a lot of spam. But there are quite a few other commands to help manage comments.

$ wp comment delete $(wp comment list --status=spam --format=ids)

Resources