 Before i get started, i need to volunteer. Somebody that the laptop Open, that would be willing to do a thing in the talk. You can do it from your seat. You don't have to get up. Back there? that guy. Just when i call on you, be ready to Go to wordpress.org and download core and unzip it. That's it. i'll explain it in the talk. You don't have to show it to anybody. If you approve your work, we're going to do that. Cool. All right. Everybody ready? we're ready? House ready? all right. I got a lot of slides, so pay attention. I'm dwayne. You can find all my stuff at mcdwayne.com For this talk, all the slides, all my github repo. Very quickly, i'm dwayne. I work at a place called pantheon. I'll get back to that. I love comic books, improv, Let's sing some karaoke tonight. I like knitting as well. You can find out more about me on twitter. I love twitter. Hit me up on twitter. I love it. If you could take a picture of me in Front of this picture, it would make me happy. And then tweet this out. Thank you very much. Thanks, ratio. Because this is an ongoing project For this year, for 2018. 2017, i spoke like 27 times and Do anything fun like this. I work for pantheon. We are a website management platform. It is elastic hosting. Any size website, you can throw it. And all sorts of awesome tools. Like the wpcl. I work with pantheon out of the box. But that's what we're here to Talk about, not where i work. But why the heck am i talking About word press command line interface? Because i believe you don't know the why of something. You don't really care about the whatever. What's down to this? Just raise your hand if this is Not true of your life. Yeah, we all do the same Things over and over again and over again. Stop repeating yourself. It's a core thing of computer Science. Do not repeat yourself. Dry. It's a thing to live by. Because robots, you can tell them what to do. And they're really, really good at doing the same thing over And over and over again. And doing really fancy things That i could not do myself manually if i tried for ten Years. Maybe ten years. But after a while, i would just get bored making pancakes. But now i'm ready for my magic tricks. Chris, if you are Ready, sir, on the count of three. Oh, wow, this is really small. On the count of three, you're Going to go to word press. Don't load it up yet. Okay, somebody else. This guy. On the count of three, you're going to go to wordpress.org And download core and unzip it. Ready? We're going to race. Ready? Mark, get set, go. Wow, there's really internet speeds in here really slow. You got it unzipped? Both of you do? All right, i have lost this race. I was supposed to show you that this is just an apache server And it's like saving it. And oh, yeah, here's my site that Built with menus that goes in apache server a second ago. I forgot to show that. It goes to my website. And this is 2016, the best theme ever. My twitter, google, even e-mail me there. I can play magic food. Oh, it didn't load the other Thing yet. I caught it mid-build. I can play blackjack. This is a fun game. Yeah, but i built this site and at the same time it took you to Download and unzip and sit there and look at me a little bit. I made a youtube video of exactly this and if you want to see The slides. Everything i'm going to show Today, i made animated gifs or videos of. So if i'm going way too fast, it's in the slides. Go find those. So what the heck just happened? What was that? What was that crazy site that i just built? And what was all this stuff running in the background that did Stuff? What? And if you notice, fun, stuff's in chinese on here. Hong Kong chinese. Just for the heck of it. Anyway, so what the heck did i just do? Well, a little quick history of the internet and computers. There used to be punch cards. This is actually how the Whole computer thing started is punch cards for wombs, actually. And they gave the idea of babbage and those lovely associates That, hey, we can make other machines do other computational Things. And eventually someone says, Instead of putting these cards in a thing and having it batch Process everything, what if we just put commands in one at A time and just typed them in. And they said, wow, it's a Really, really good idea. And there came unix. And somebody said, what if we just stacked these on top of Each other and let the machine read those in an order. And we got scripts. And then wpcli happened. I said it was a very abbreviated story. But that's it. That's the entire history of the internet, What you need. So wpcli is just a set of Tools, scripts, really, and php that are for managing Wordpress installs. And it's out on github. It's open source. You can go out there and please Contribute. Absolutely. It was maintained by These fine people. Christy and andrea have the credit Of creating this thing back in the day. Daniel took over and in 2017, january, this got rolled into wordpress.org as part of the Official project. Very, very proud of that. And wpcli.org is the shortcut to get you there, but all the Docs go out to wordpress.org now at this time. Which is awesome. So how do we do this thing? This is a tutorial. If you want to play along at home. Good luck. This goes really fast. So first we have to install this thing. Locally are on a server. We're going to need some stuff for that. Everything in this deck is Copy-pasted from wpcli.org or developer tools somewhere. Or the tool itself. But you're going to need bash, Our units like environment for those windows users. I've seen this work inside of get bash and bash on a bunch Of windows. But really, if you got local by Flywheel or the lando or any of those tools, it's right in There. You don't really need it to install it Separately. Anybody here on php5.3? Good. You should be on seven or later. Please. But this is what you do. This is how you install the thing. I know this is the scariest Part of the whole process. If you've never used the command Line before, if you're not like me and you go to the internet To check your weather by hitting the telnet server over at Weather underground still, which is still up and running since 93, nonstop, well, about 70% of the time it's nonstop. And you're like me, what the heck is that? It's really easy. It's like, hey, over the internet, copy the information from The url and put it in a file called wpcli. Which is a packaged up set of php files ready to go. Change the permissions to make that executable on our Machine. Now let's move it somewhere useful. If i type wp, i get that. The whole process looks Something like this. Then type wp. And it's just there. It works. That's the test screen To say, hey, this does the thing. Success. That's the hardest part of using wpcli. If you're scared of using it because, wow, it's going to be Hard to learn. No, the hardest thing is running Three commands on a terminal. That's it. After that, we can do a lot of crazy stuff with it. And fun stuff with it and very, very, very useful stuff With it. And at the end of the day, save a Lot of time. Here's some of the stuff that we Can do that we're going to go through today. Again, everything i made is animated gift. So if you're lost and you need to go back and consult, it Will be there. And of course, the ultimate Authority of this is the commands themselves. You can go to developer, well, the url, give these commands. But also, these are built into the tool itself. I'll come back to that. You should know the Structure of commands if you're going to attempt to Use this tool. Everything you'll ever do with Wpcli starts with wp. And then a command, like Theme or plug-in or up or a bunch of them. And then a sub-command of that, like theme list or plug-in Update or plug-in install. And then some parameters. Like we saw in the last talk, dash, dash, activate. Well, activate a plug-in that you've just installed. That's what happened on that script i ran earlier. There's some global parameters that will always work on Anything you run, like prompt, which we'll get to as a fun one. Quiet, which just makes it quiet. So it doesn't give you very Verbose messages. And then there's some situational things. This varies around, but dry run is one of my favorites, Because it says do it, but don't actually do it. Tell me what you would do if it actually ran. And i have find a lot of safety in that. Because sometimes, like, that makes no sense. Let me go back and see what i'm trying to do. So you can type wp help in front of literally anything In the entire tool, and you get something that looks like this. One of the most beautiful parts of this project and why i get Excited about it, one of the reasons i get excited about it, Is all of the help docs come from the code itself. When you go to the website, all of that content came from the Tool being built. It's there. I learned wpcli on an airplane. Not kidding. I was bored. It's like i should learn this tool. And it was just wp help in every command and walk through It and learn the thing. So let's dig through the Command list. How am i doing on time? Awesome. I am right on schedule. So we can do things like download core that fast, depending on Your connection, of course. You can do things like who Loves making wp config php by hand? Nobody. So have a machine do it for you. In fact, i never remember what to do, so i just say Hey, i need these things. If it doesn't have a square Bracket, it's mandatory. If it has a square bracket, it's Optional. This isn't the most secure Container environment in the world i'll admit. But i got there and it generated it. And then you've heard of the five-minute install? This is the five-second install and how i install all of the WordPress sites that i ever work with. I just run dot bash, that build script from my desktop And it just runs. And it builds me sites that do Exactly what i want them to do. Search replace, arguably the Most powerful tool in the whole arsenal. This is how i found this tool in the first place, because i Completely hosed all of the urls moving between environments For a site that i was building for fun. And i said, how am i going to fix these urls? And it turns out it's old string, new string, and it Just does it. So here, hello world. Let's replace that with the first demo post. And there you go. And if you look back to the Example site i was running earlier, yeah, that's how i Replaced wcmi rocks right there for just another WordPress website, because it's not. You guys rock. With wpcli's search replace. You can do this. I don't have it in the slide, but you can do this Against sql or if you throw precise behind it, you can Do it all in the php. Do a php search replace. This comes super powerful. We need to combine it with things Like export. So if i'm going to migrate from my Dev server to a production server, i can kick out a new Database with the urls completely replaced, ready to Import, and it doesn't touch my dev at all. It just makes those changes in the new export as it's Doing it. Pretty powerful. That's where we talk about themes. And this wonderful fun Theme i found called 90s retro. Yes, of course you can install Themes with this. Here i'm actually activating it at The same time, but instead of going through and waiting for Screen paints, which just drive me nuts, waiting for screen Paint, waiting for screen paint, waiting for screen paint, Push a button, wait for screen paint, wait for screen paint, No. Type the line, there you go. Then you can do things like theme mod. I changed the background Here, which is covered up by an image on this particular one In the world. Badass. Which is the ugliest yellow. But it's fun to say. You can delete themes. How many people have themes That they are not using on an install? Yeah, get rid of those. If you're not using them, they're Dead code waiting for a security vulnerability. Seriously, get rid of them. Theme delete and clean up After yourself. It's that quick. Let's have some fun with posts. We can generate posts. That's easy. Sorry about the screen resolution on these. I don't like working with empty sites, and i really don't like Empty things either. So here i'm curling in. First i'm just building empty demos. Then i'm curling in data. This time baseball orm. Baseball ellipsum. And there it is. There's my baseball low arm ellipsum. I can do interesting fun things like post list. Which of course i can, because i'm in bash, just export. And i can throw a format in there of csv or json or xml if i'm Really trying to do something. And there it is. A post list that i can full control over site. Who's ever inherited a site and how am i going to sort through These posts? Yeah, this is how you do it. Post delete. I thought i replaced this image. So here's a post list. And let's just delete something Real easy. Delete two. This is the wrong image. Apologies. But it shows the thing. I deleted post two, and it's no longer there. Site empty. Wow, this is a powerful command. How many get to the end of building a dev site? I've got to get rid of all these posts now. Yeah, site empty. It just does it for you. Anything that's content, just kick it out the window. We don't need it anymore. I'm ready to do something Else with this site. Go from this site to site empty. Yes. And just like that, it's gone. They're just gone. Menus. One of my favorite fun things to do. This varies wildly theme to theme. So i will tell you don't Not write a one-time. I'm going to do this on all themes. Because it might not work. Themes vary wildly on how Menus work. So in this particular theme, I'm showing the wrong gif here. I'm doing site empty the Right way here. Anyway, here's where it works, Where i'm throwing more in. I name the menu, put it in a Place, place that menu, and then populate that menu. Those three. So if you're always building the same Kind of menus, all you have to do is swap urls and content Descriptions, and you basically have a scaffolding for Building menus very, very, very quickly. Talk plugins. Again, i have a lot of slides, A lot of content, and we're buzzing along. Of course, you can install plugins and activate them as we Saw in the last talk. You can also update them. This is a pretty good way to use it. This is one of the Things i do when i automate the updates on my website. It relies on this feature. The fact that it can see if Something needs updated, and i can run the update. Scripts do that for me. You can do it either Individually. There's dry run telling me what it would Do. Go ahead and do it when i Release dry run. I can also say all. You probably shouldn't run dash dash all on a production Site. This is a great argument for Dev environments. In a dev environment, blue Something up, let's go fix it. You can roll back. In a live environment, a little bit more embarrassing. Then you can do fun things. If you know, this is Actually guttenberg's installed doing this. If you know the short codes that you want to populate A post with to do something like make a functional blackjack Game and magic food happen inside of an actual post, Well, just make the post from a command line when you Install the plug-in. That's two steps, and i Have working functional things on my site from the time It's first fun up. Users. Of course, you can do things like create users. In fact, this is one of the other things i wanted to demo Live. I only got two live demo things here. Okay. Command not found. There we go. We're back to normal. Sorry if you can't see this. We're going to run dash user. User. Can't find post 22. Of course, you can't find Post 22 because it aired earlier. So let's look at wonderful world of vi for a second. Actually, i won't edit. But you can see here at the bottom, I've created one, two, three, four, five, six users. The users are now because when i said user list, Normally a user list as i show over in here, a user list Will show me what users are on the site, including e-mail. For this demo, i put up a live form and said, hey, If you want to help me with my site, bob, brad, chris, He put his full name in there, me, guy, and jim, real people. I said, okay, fill in this form. And they filled in and went to A csv file. They got piped out that i Uploaded here as data as a data one csv. Script ran through, created all of them and then created Comments for all of them on a post that doesn't exist Because an error happened earlier in a process. Anyway, where i'm saying only the user names exist is Because when you display anything from a list, you can Regulate it to just show certain fields. So how you would do that. Actually, we'll do this. Vi user. Lovely vi. This is bash script. And that's what i would Love for you all to take away from here. The wpcli is awesome in a time saver and in of itself If you're just getting to the command line and doing Everything. But you can also start doing Clever and very useful things with bash scripts. The real bash scripts i use for generating sites on my own, My demo sites. Wow, this is really small. Changed all of your resolutions. This is this. It's a laundry list of things i turn on and off, but when I create demo sites, bam, i run one script and it just Does it. All the terminal stuff i'll Get back to you later. But we can start using These things to do things creatively. Back to users. Users can do things like add roles. Do you know that a single user can have multiple roles within Wordpress? Absolutely. Did you know that you can modify The capabilities of all of those users? You can. Or all of those roles. You can. You don't have to have a plug-in or Nothing. Just do it. There's a wonderfully documented out on roles and Capabilities and you can start mixing and matching. So if you want a subscriber who for some reason has plug-in Edit rights, you can do it. If you want authors that can't Delete things, you can do it. Whatever you dream up. It's just part of core. User list, delete. You can delete any user. You can do it in batch. This is great if you're working with a lot of people And suddenly groups change. You need to revoke access Immediately. Cooking this up with a User-delete script. Let's kick them all out and We're done with it. I'm wrapping up. Database. How many people love looking at Database tables? it's good to know what those tables are. So db tables does that. You can do fun things like export. And then db cli. Yeah, my sql cli is there. Anything special to get to it. Wp cli will get you there. Wp db cli gets you to the my sql dbi. My sql cli. You can do fun interesting things Against your database if you so choose. And if you mess things up, there's this feature called db Reset. It will shake you back to nothing. And then you can import that back if you did earlier and You're right back to where you left off. First time i saw this blew my mind. Thanks for this awesome magic trick. This is useful in real life if you blow up a database. And then we get to the really awesome stuff. I've been saving the best for last. Everything else is grinding along. Skaffold. How many people use child themes every time? No exceptions. You're doing it right. Thank you very much. Parent themes are there to catch In case your child theme completely gets hosed and Something just goes horribly wrong. Child themes are a pain if you manually construct them. I will admit this. Child theme is one line to run Where you name the child theme, tell it what parent you want, And it puts everything in place for you. Everything. You can even run activate the same line. And now i'm running a child theme of 2016 on this site. In this particular example. This works on almost anything. I started to do it with 2016 because i like 2016 a lot. And i think it deserves child themes. Plug-in scaffolding. We saw in the last talk he used this to make his plugin, But he also turned off the tests. WPCLi will build you test suites until you the scaffolding. If you dig into what it actually builds, Here i'm about to show it more. Here is the test framework built for me. I just got to fill in the dots. I got my unit test almost built from the time i started My plug build. Plug-in build. How many people make plugins at all? Any way shape or form. How many people is Gutenberg ready with your plug-in? Yeah. Really easy way to get there is here. It's not going to do the work for you. It's not going to put the actual things in place, but it's Going to give you the framework of what your plug-in is. If you look at zack gordon's information on it or Anywhere else, the codec or the github repositories, This is the framework of how to put these things in place. This is part of the core tool. Just a scaffold block, And you are on the path to making yourself Gutenberg ready. And we need to work on that. Language. Last one. One of my favorite things about WordPress is accessibility. I am very proud of 100% Accessibility score on my website. And i think that in general accessibility of making everyone In the world able to use a tool is a great thing. Part of that is language. Absolutely. I chose hong kong chinese or chinese hong kong at random Off the list because it started with a z. It was one of the last things i saw. But that's it. It's that simple to Translate to another language. You can develop in your own Language and have it translate over. And all the admin screens become whatever you say. It doesn't change your content. But the site itself now is in That other functional language. If you are working with an International developer, flipping back and forth between Languages is literally one line. It's activate. Bonus commands. Stuff i didn't know where else to put. But i love it. Wp shell. How many people love running an arbitrary php on a server? Yeah, it's scary. But you can do it. If sometimes it's really, really helpful. Like, where on earth is this doing? Let me get this info and just spit it out in terminal. Wp shell gets to that access. This is globally on all the CLIs that this works with in. Get back to that in a minute. Who loves cron? Yeah, you can run it from here. For those of you who don't love cron, it's actually pretty Good if you know what, if you spend the time to Actually investigate deeply. But you can do things like Run all or activate specific cron events. And it makes testing this so much easier. Because wp cron, through the gooey, you can. But this just makes it a lot faster and easier. There's so much more to it. This is meant as a precursor Of just to get your taste of what's going on. You can go back and look at all these slides to see Functional examples of everything that works. I'll fix those slides that were messed up earlier. But guess what? This is extensible. You don't have to take it off the shelf and say, oh, that's all It can do. No, it is very straightforward To extend this out. I have not had the person Who will need to. But one of my favorite talks In the history of the world is right here, wordpress tv. You look at ben burn, accelerating custom. And this is all in the slides you can have. Accelerating custom. He works for a company That uses the same theme everywhere. But it's a very minimal framework. They built their own scaffolding tools out of wpc li called Produce. And it puts it in this thing called Crate. Which is the name of their theme. Clever idea. But this in action is like, Well, that's just insert mustache code and just modify Those variables. And that's how we'll do all our Custom dev. So you can give a completely Custom site where the standards are very rigid, but you Can do anything inside of this wonderful framework. And all of their devs can communicate a lot faster. They can build faster. That talk was amazing. It blew my mind last year when i saw it. So go check that out. That was in seattle. Wordpress. Our word camp seattle. Wpc li also works in other clis. I work with pantheon and part Of the reason i love wpc li is we use it a lot. But we have our own command line called terminus. Command line tool called terminus. So for a lot of things i do, I'm going to jump back to my terminal. Sorry, this is really small out there. Let's do it clear. I can do things like, hey, Let's go look at the plugins that are actually live on my Active site because i wrapped terminus, which calls my Platform to do a wpc li call against a specific site and Then pass in that command. So here's what i'm actually Running. Turning Gutenberg off and on Depending on the day. I'm still testing it for a Bunch of stuff. But i use wp markdown Still for how i write everything. It's also desktop server. Dsi wraps it in. Flywheel has this pre-installed. Local by flywheel has this pre-installed. Just ssh into that Site and it will pop up command box and you have just type Wp and it's just there. This is true of some platforms. Your mileage may vary. Sometimes if you have a Vps you can just install it and run it. Anyway, i'll leave this up while i'm getting questions. I don't know. I'll be honest. I very rarely personally develop ooo commerce. But does anyone know? Can you wpc li export products? Yes, we believe so. That's right. Woo has their own set of wpc li commands. So absolutely. I wouldn't go investigate that. I personally don't have the experience on that. Yeah, to run it actually it's going to need a working Database, doesn't it? Yeah, you can install this to install Wordpress. Yeah, once the far files, as long As you run a php 5.3, whatever, honestly just run 7. That's what i'm running. Or later, 7.0, 7.1, 7.2. It'll just work. Far files, pretty lightweight and Should just run. It does expect a database to be there. It depends on how you're doing it. Yes, the short answer is yes. If you're using a tool like pantheon, You just point it at the individual sites for the command. You can also do remoting. Sean Hooper has a whole talk about that where he manages hundreds Of sites through wpc li. You're going to have to do a script To do that because you're going to have to hit multiple Remotes at that. But it's all, you can rate Your own bash anything. And it can do multiple commands. I think i'm right there and then over there in the interfere. Okay. That's not stupid. You're going to use get to do get. This is to manipulate the Install itself, not to manage code away from. Now you've said that. It'd probably be worth a go look And see in the command list, but if you're using github, I would say just use get. It's pretty efficient and fast. You can tie things together. Right here. You had a question? i thought you did. Can you create like an underscore and then i generate the site. One of the scaffold command is underscores. Then you can throw in a ton of stuff behind that, have it Curl in anything you need and yeah, build. And it's extendable so if it doesn't do it out of the box, Crack it open, make it do it. If you can do it with php, You can absolutely do it with command line. And then right there. No, it was back there and then you. If you run porcelain, it will show you the password. Porcelain is show me what i did and give me the valuable Information and you can make it be quiet so it wouldn't show Up at all. It would show you running the command. It wouldn't show you the export but if you're trying To avoid putting those data in the terminal itself, just Upload a separate config file from somewhere else and that's Your safest bet. Yeah, that was one of the Prompts. They weren't really, really fast but I could just run that again, actually, where is my other Terminal. I'm using, oh, crap, i'm in bi. Hold on. I got to remember how to Quit bi. Okay. I don't know why it's cutting off the bottom here. So if i do wp core config dash dash prompt, We can just walk through the prompts here real quick. So, yeah, database password is right there. What was the question? Oh, yeah, yeah, yeah. Prompt is an all or nothing as far as i know. However, it's just bash so if you wanted to pass that in From another data point, that's what i did in... Crap, trying to do that thing again. Kill that. Wow, that's annoying. No, no, no. Kill that. Just work. Can i just do this? I can just do that. It would be hilarious. I can just do that. That's not what i wanted to show at all. That was the opposite of what i wanted to show. Kill that so i don't actually... Yeah, here it is. Here's like how i pass it in. There's one thing. But no, you can't prompt This in all or nothing as far as i know. And then... oh, i was answering the other question. This one. Mass add, user add. Here, i'm just passing in a bash data field. It could be a csv, it could be anything. And all you're doing is changing the delimiter. Here's the old delimiter, or the new delimiter is comma. In this particular case, because it's csv, it could be Part of json, it could be anything. And then just pass those variables in at the time. How do you do it that way? Yeah. If you're already are super familiar With shell scripts, this is going to be an amazing weapon in your arsenal. If you're not familiar with shell scripts, it's fun. It is really fun to make computers do fun stuff. All right. How are we doing on... Whoa, we're about right at time. Another question? Yes. It was dsh, absolutely. It needs a unix-like environment. So i've run this on crash bang, free bsd. Puppy linux has issues, but puppy linux always has issues. Damn small. I've tested this on a lot of things. And it doesn't matter the terminal. If it's got php present, And it can actually communicate properly to a database, Not everything can, then yeah, we'll run. Yeah. So i'm going to kill the screen so We can walk out. So once a week, cron wakes up And pings circle ci to go see if any updates are needed on my Site, the site that i was showing earlier. If they do exist, let's go try to update them all in a separate Environment, then run backstop j s to see if that matches What's in production. If it matches, this will kick It all out to production. If not, send me a slack message. So you can do things like that based on the information You can feed off of bash scripts and wpcli. That's my favorite use for it. All right. Thank you very much. Thank you.