 I'm going to move kind of quickly because I want to make sure that we're able to sort of try to get back on track. But hello everybody, welcome to Up and Running with WPCLI. My name is Steve Cronwell. I'm at Steve Cronwell on all the social networks that matter. If you're the kind of person who wants to grab a copy of the slides now, they are available at stevecronwell.com slash slide slash WPCLI intro. They're also at the bottom of each slide, though very small, and I will be tweeting them out following the talk. How many people in the room have worked with WPCLI before? Okay, so they're a good mix of old hat, new hat here. For those not familiar, WPCLI is an open source project that lets us interface with WordPress from the command line. It's really fantastic for maintaining sites and automating tasks, because if you're like me, you like to automate all the things. It's also easily extended by themes and plugins. So as a plugin developer, I can write a plugin, package a WPCLI command with it. And then if you have my plugin installed and activated, congratulations. You also have my WPCLI command, which can be a frightening thought now that I think about it. There are a couple common commands, though, just out of the box that you get by installing WPCLI. So if you're new to WPCLI, these may be of interest to you. First, perhaps we need to install WordPress. So we can say WPCORE download. And that, believe it or not, downloads WordPress core. If we wanna get through that famous five minute installation in one command, we could do WPCORE install. We tell it the URL, the title of the site. We give an admin user. We give an admin password. Please don't see my password. It's super secure. And the admin email. If we need to update WordPress core, there is a security issue. And we need to go, I need to update this now. I don't wanna wait for the automatic updates. We can do WPCORE update. I should say we can also do, if you're converting from a single site to a multi-site installation, WPCLI can handle that. If you need to verify checksums, because of course we're all verifying the MD5 or SHA1 checksums on everything we download, right? No? Where's Aaron? He would be so sad. If we're managing our plugins and themes via WPCLI, we can do this. So we could go WPCLOGIN install WordPress-SEO. If then we need to, say, install it and automatically activate, we could add a dash-dash activate to it. So this will install and automatically activate. If we need to explicitly activate the plugin, we already installed it, and we go, oh yeah, I need to activate that plugin. WPCLOGIN activate WordPress SEO. Deactivate, just the same. WPCLOGIN deactivate. You're getting a sense of how this is all going. If we're working with themes, very similar, we can go, I need to install a theme, and I want to make it the active theme. Or I want to delete a theme. Now, this would be a theme coming out of the WordPress.org repo. Though you can specify, I want to use a theme from this zip file or from this Git URL. So it's very flexible that way. We can manage our users in content. Maybe I need to create a new user. I have an almost three-year-old now named Emily. So maybe I need to do wpusercreateEmily with the role of Toddler. And it'll create a new user. It'll generate a password and send out the email and everything. Maybe I need to reset a password. I work with a guy named Forgetful Dave. And every week, Dave's like, I forgot my password. I don't use a password manager. Dave hates me. I don't actually work with a Dave. But I could say I need to trigger another password reset. So wpuserresetpassword, David. Damn Forgetful Dave. We can manage our content. We could go do wppostcreate to start authoring content. We can update stuff. We say wppostupdate ID of whatever the post is and the specific fields we want to edit. We can generate content. So especially if you're a theme developer and you need to be able to scaffold a bunch of content to show, like, this is how the archive page works. WPCLI has your back out of the box. So in this case, wppost generate dash dash count 10. We'll generate 10 posts. And we can say we want to make these pages. We want to make them a custom post type, whatever. We can also do the same stuff for terms. So in the same way we created posts, we could go, I want to create some taxonomy terms. I want to update a term. I want to generate a bunch of taxonomy terms. All of the stuff you get for free, which is awesome. Common database operations. Rather than saying, oh, I need to go in and I have to know how to do all of the SQL commands and I have to work with SQL on the CLI. God forbid. We can say, hey, WordPress, you already know how to talk to my database. So let me use you. I'm going to do a database dump. So I'm going to say wpdbexport and then the file name. So backup.sql in this case. If I want to import that, I can do wpdbe import backup.sql. WPCLI also comes with a powerful search and replace. Now, if you do a regular search and replace on a SQL dump file, you are very likely going to run into a scenario where you have serialized data that it's expecting, oh, well, example.com is, that TLB is three letters and all together it's what, 10. But you change it to example.local, which then goes from 10 to 12 and then you're like, oh no, the serialized data is all broken. I've ruined the site, it's terrible. WPCLI, the search and replace that it has out of the box will do a smart, it'll deserialize any serialized data, then do the search and replace, then reserialize it so you won't be pulling your hair out. WPCLI gives us access to some of the things that WordPress out of the box isn't necessarily going to show us. Some of the WordPress internals. So we can do things like play with the cache. We can say I want to set a cache key in the object cache. I want to retrieve it. I want to delete it. I want to flush the cache from WPCLI. Those commands are all baked in. We can do the same with transients with the very same API, but WPCash to WPCtransient. Easy, yes? It's also going to give us visibility into things like WPCron. I won't get into examples here, but if you're like, hey, what scheduled jobs are coming up? What's going on? WPCLI has your back. WPCLI also comes with scaffolding tools. So if you're a plugin developer, you can say, hey, I want to be able to automatically scaffold a new plugin. The nice thing is when it scaffolds the plugin, unless you tell it not to, it's going to give you the plugin with all of the test scaffolding you need to actually write unit tests for your work because we're all testing our work, right? That was like the biggest lie that anyone has told me. Come on. That's true. So anyone who doesn't know Norcross here, yeah, because when I'm trying to catch up on time, I'm like, oh, let me go off on a tangent. Never mind. I'm that guy on the team who's like, eh, we should test everything and he's the guy saying, shut up, Steve. If you're building themes, you can say WPC scaffold underscore S, which will generate a new WordPress theme based on underscores, which is handy. We can scaffold a child theme. So if you have a parent theme and you're like, well, I need to create the necessary files to have a child theme, boom, WPCLI. We can scaffold a new custom post type. So if you're working with that and rather than going through the Codex and going, oh yeah, how do I do this again or using some of the generators out there? You can just say, this is the custom post type I want. Fill it in for me WPCLI. We can do the same with custom taxonomies, which is really nice. And if you're cool in working with Gutenberg, you can already generate a block using WPCLI, which is pretty neat. Writing commands is a whole talk in and of itself. I've actually given this talk several times called writing WPCLI commands that work. And it has to have the hook. That's part of the official name. If you're interested in that talk, if you wanna get really like drinking from the fire hose on building commands, that talk is available at sleevecrumble.com slash slide slash WPCLI. So same as this, but without the intro, welcome to the 201. And there's a video from loopconf 2.1. So you can watch that now for free. Congratulations, you're all going to be experts. For those who don't wanna go through 45 minutes me babbling, a very simple command. Basically, we end up registering using WPCLI colon add command. We say, okay, this is what I want my command to be called. So in this case, amplify. We're going to pass it any sort of callable. For the sake of brevity, I chose to use a closure here. So we're saying, okay, I wanna get some arguments. And then I wanna output whatever was passed in the first positional argument, but string the upper and append three exclamation points. Because amplify, aka to make louder, the way we do that is all caps in three exclamation marks, right, that's, you can see the doc block up here, it describes it and says what it does, and it describes the options available. And then when we run WP, amplify, hulk smash, instead of just hulk smash all lowercase, we get hulk smash. And I'm sure I just clipped the audio. So you're welcome WordPress TV. So again, we're just trying to catch up on time here. So I'm gonna end it there. I wanna thank you very much. My name is Steve Cronwell. I'm a senior software engineer at Liquid Web. I blog very rarely at stevecronwell.com. Slides link and I will be around for the rest of the conference. Oh, I get the answer. Yes. Yes, I can talk about it because she tweeted about it. So Carrie Dills, many people in this room know Carrie Dills. Recently, she had a client who needed to move from shop with two Ps, which was a very popular e-commerce platform a while ago, less so now, but a WordPress plugin. And she's like, I need to move this customer into WooCommerce. And I'm like, I want to do that for you. So, and I had Chris Lemma's blessing to basically spend a week like, I'm writing a WPCLI command to migrate all of the product data. And I didn't have to worry about all of the configuration and there were very few orders on the site. So she's like, yeah, don't worry about that. But I got to write this thing that it's now out there on GitHub, open source. I think it's liquidweb slash shop to WooCommerce. But yeah, a WPCLI command to go, hey, I'm gonna migrate all of this stuff over here. So that was the one question. Again, I will be around, but I want to now see the stage to Kyle because it's Kyle. So thank you very much.