 If you want to follow me on Twitter, I'm on there at John Billion. I'll tweet out some links a bit later on to things that I'm talking about. What do you think of when you think of the WordPress interface? It's probably this, the admin area of WordPress. But this is actually just one way to interact with WordPress. For example, there's the admin area, there's Ajax, there's the REST API, XML, RPC, RSS feeds, themes themselves. These are a way of interacting with WordPress and leaving comments. These are all interfaces to WordPress. So WPCLI is another interface to WordPress. It's the command line interface. The project's goal is to offer a complete alternative to the WordPress admin area. For any action you might want to perform in the WordPress area, admin area, there should be a compatible WPCLI command. You can find out all the information about WPCLI on wp-cli.org. It's a separate project to WordPress. Unlike some other CMSs such as Drupal where you get the CLI tool built in, this is a separate project. It's managed on GitHub if you want to contribute, all of the information is on there. I'm not going to talk about installing WPCLI. It's a fairly straightforward process. Also, if you use some WordPress-focused hosts such as SiteGround, you'll find that they already include WPCLI, so you don't need to worry about installing it. And here's the interface. It's not very intuitive, is it? How do we get started with this? This doesn't look a lot like the WordPress admin area. You can start typing things in here and see what happens. That's probably a good approach, yeah? A good way to get started though is to take a look at the built-in help manual. WPCLI has got a complete help manual built into it. You can type wp-help to get you started. This will list all of the available commands for WPCLI. It's a good way of learning which kind of commands are available, what sort of things WPCLI can do. You can also type wp-help followed by an individual command name, such as plugin or user, and it will give you all of the available options and information about that individual command. But quite often what I find is I start typing out a command and then I realize I can't remember the rest of it, so you can just type dash dash help on the end of it, and again that will give you the same help information. But there's a really interesting feature of WPCLI called guided interactive mode. It says flag here called dash dash prompt. What this means is you can type wpn in a single command and you don't have to remember all of the rest of the flags that are part of that command. It will prompt you for those options. So a good one for this is adding a user to your site, for example wp-user-add. Instead of having to remember the name of all the fields for their username, for their email address, for their role, you can type dash dash prompt and wpli will guide you through each of those fields. It's a really good way to get started using WPCLI. So dash dash help and dash dash prompt. These are the two ways to really start getting used to WPCLI. There's also an online version of the help at wp-cli.org. You can find a handbook link at the top there. That is a really good introduction to WPCLI and all of the available commands are on wpcli.org as well. Now the good thing about the commands on the WPCLI website is they are actually generated directly from WPCLI itself. So the documentation is always exactly mirrored. So if you fancy browsing some commands to see what commands are available you can go onto the website or you can type wp help into WPCLI and that will give you exactly the same information. Now the build process for WPCLI builds the documentation on the WPCLI website. Another top tip is that commands generally follow this structure of wp followed by a noun and followed by a verb. So for example wp user creates is a command that creates users. wp plugin install is a command that installs a plugin. wp post meta add is a command that adds post meta. Now you get the idea that's generally true but not always there are a couple of exceptions. For example wp import. It's a great WordPress tradition having an exception to all the rules. But as a general rule you'll find that all the commands are structured in a very similar manner. Now there are two ways to use WPCLI. So far I've been talking about one-off usage in the terminal. For example here we can type in directly into our terminal wp user create and then the details of the user and that goes ahead and creates the user. You can type in a command such as wp plugin list and this is a good example of the kind of tabular output that you'll see a lot in WPCLI. It's really useful. It's really clear way of representing data in your terminal. You can also specify which format you would like for the output. So the default is a table that you can get CSV output, you can get JSON output, YAML output, several others but this is generally the interface that you're going to see on the command line. But this is the only way to interface with WPCLI. You can also script WPCLI typically through a bash script. So for example here we've got a script that downloads WordPress if it's not already there. It creates a configuration file and it will populate it with the details that you type in. Then you can carry on from here. You can do a complete WordPress installation. You can set up users. You can set up the initial plugins and themes and you can script all of these. So next time you want to set up a WordPress site instead of doing it manually, instead of downloading WordPress from the WordPress.org site, you can just run this script, type in a few parameters and bam, it will go through the whole process of downloading, configuring and installing WordPress. This is really useful for spinning up a test website if you want to test something out with WordPress. But it's also handy every time you need to start a new website for example for a new client. Instead of going through all these manual steps each time, you can have a nice shell script that you reuse passing some parameters that are relevant to that project and bam, you've got a new WordPress website to spin up. So this is really where the power of WPCLI comes in, is scripting it to do what you want when you're finding that you're doing repetitive tasks in WordPress. So the WPCLI project claims to be a complete alternative to the WordPress admin. This is mostly true, you can do almost everything in WPCLI that you can do in the admin area and you can also do more things in WPCLI than you can do in the admin area, I'll get to those shortly. So let's take a quick look at some of the admin screens in WordPress and see what the corresponding commands are. So probably the most common one is managing posts because it's managing content in your WordPress site. For example, WPCList, this will show you a nice tabular output with the posts on your site. You can create posts with WPCLI by passing in all of the parameters, for example the title and the content and the author and the category and the tags. This is an interesting one, WPCostEdit, this will actually open up the editor that you've configured in your command line to edit the post content on the post. For example, if you've configured Vim or if you've configured PHPStorm, it'll open up that editor, you can sit there and type out a full blog post for example and save it. Once you close it, WPCLI will save that back to the vectors. You can manage your categories through WPCList and passing in the category, taxonomy name and the same for post tags. So so far all of those things that we can do in the posts menu we can do equally as well in WPCLI. You can manage media in WPCLI, unfortunately you can't see thumbnail images in WPCLI. I'm sure someone's tried to write an ASCIR interpreter but we haven't got one yet. And there's a couple of things you can do which you can't actually do yet in the admin area. For example, WPCmediate import will take a full URL to a file and it will download that file, import it into WordPress and save it as an attachment. That's not a very easy process to do manually through your web browser. And WPCmediate regenerate. Now you may have heard of a plugin called Regenerate Thumbnails. If you change your thumbnail sizes and you need to regenerate all your thumbnails you might have tried that plugin. But that functionality is built right into WPCLI and it's much faster, it's much more performant and you can target specific attachments if you want, so all of that is in there. Managing pages is just the same as posts. The difference is that we use a post type flag here to specify the post type and again you can create pages and all that kind of stuff. Comments, you can manage comments through WPCLI. The standard method is just to list the comments that you can also approve individual comments, mark them as spam, all the same kind of comment management tools that you've got in the admin area or in WPCLI. Themes. Again in the admin area of WordPress if you're managing themes you get those nice big thumbnails of the theme. Unfortunately we don't get that in WPCLI but apart from that you can do all of the theme management that you'd otherwise be able to do. For example you can install a theme and you can activate it immediately in one step. You can even set theme mods if you know what the key names are there for the individual settings for a theme you can set those directly in WPCLI. If you're feeling really brave or really adventurous you can even start to manage widgets and nav menus in WPCLI. It's not very easy, it's not very intuitive because you have lots of parameters that you need to use but for example if you're building out an automated script that manages widgets or nav menus you can manage those completely through WPCLI. One thing you can't do though is bring up the theme editor in WPCLI. There have been some attempts to do that but so far we haven't got that in WPCLI. Plugins. This is also a function you'll find yourself using a lot. The steps to installing a plugin in WordPress is a bit of a slow one. Using WPCLI you can quickly install and activate plugins with just a few touches of the keyboard. You can also search plugins. This is really handy if you're not in the mood for searching through the admin area of WordPress just put in a search term to show you all of the search results and again you can then go ahead and install plugins from that point. User management. Again you can manage all of the users on your site. You can list users, you can search users based on the user name or their email address or any other field. You can restrict the list to roles. You can create users. This again is a really quick way of creating a user instead of having to fill out all the fields in the admin area and you can update users quite often if you have a user who's forgotten their password. The easiest way actually is just to update it for them and then go and send them a password. Finally we'll take a look at the settings. So all of the settings screens in WordPress are actually just an interface to options in WordPress. So WPCLI lets you get options so you can read it from the database. You can update options. For example if you've forgotten your email address for your admin area you can change that quickly. And again you can search for options if you can't quite remember the exact option name that you want to fetch for update. There's a strange exception for the rewrite rules in WordPress. These are managed through a separate command called WP Rewrite. This is really handy for the initial setup of your website if you want to always set a particular rewrite, a URL rewrite structure. You can use this command and you can do that in your script so when you set up your sites you've got your URL rewrite set up how you always want them. So those are some of the things you can do with WPCLI but why would you do that? Why would you choose to sit there and type things in the command line when you can do it just as easily by clicking, pointing and clicking in your browser? Well let's take a look. WPCLI is fast. These are the steps that you need to take to install a new plugin through the admin area in WordPress. Now you've got a fine admin area, you've got a login with username and password, go to the plugin screen, go to add new, search for the plugin name, find it in the results, click install, click active, activate. It's a little bit long-winded. With WPCLI this is all you need to do. This is the command to install and activate the plugin in one go. WP plugin install, name your plugin and then this dash dash activate flag and activate it. So when I'm working for my local WordPress websites I find that if I want to try out a new plugin I'll just open up WPCLI and type that in there and bam I've immediately got that plugin installed and activated on my site without having to go through the admin area. But WPCLI is efficient too. Bulk managing users in WordPress isn't a very easy thing to do. For example let's say you wanted to update the user role of a bunch of users you would have to individually go into each user and change that user role. With WPCLI you can run a command like this, WP user update. I will search for all of the users that have got example.com in their email address and then we'll set their role to a subscriber with this flag here. And you can see here that WPCLI just goes bam bam bam bam bam updates all of those users. Now imagine if you've got thousands of users on your site that's going to save you a lot of time and you can just let that sit there and run. It doesn't run instantly but you know it's certainly a lot quicker than going into all of those individual users in the admin area. This is actually one of the things I really use WPCLI for a lot is managing users. That's one of the areas where it really outperforms the admin area a lot. If you maintain a WordPress multi-site installation you really should be using WPCLI because it makes things a lot easier. For example you can target an individual site on the network using the dash dash URL parameter. So if we type WP plugin lists and we pass in this URL it's going to list all of the plugins that are active on that particular site on the network. User management again this is a lot easier. We can set an individual role for a user on an individual site. So for example if you've got a new user on your network and they're not yet a member of an individual site you can strip that or you can type it in and it will immediately set that user's role to the one that's specified on that individual site. Again if you've got a high number of websites on your network you'd be able to loop through all of the sites on the network and add all of those users very quickly. If you try to do that in the admin area that's going to take you a long time. Again option management this is all done through the URL parameter. There's a few other things you can do with regards to multi-site. You can list sites, you can create sites. Again I'm using the dash dash prompt flag here which means you don't have to remember the name of all of the flags so you don't have to type in the URL and the site title and the admin email address. It will prompt those and it will go and create that site for you nicely and quickly. And then a command here which you might not find, you use very often the network options so if you go to the settings screen in the network admin area in WPCLi this is technically called network meta and you can manage all of those network settings from WPCLi if you find it immediately. Does anybody know about multi-network support in multi-site? You can actually have, this is like a little known feature, in multi-site you can actually have multiple multi-sites on the same network. It's not very well known thing so WPCLi supports this by passing in the network ID there so you've got full support for all of the functionality in multi-site. Here's some things that you might not immediately think of. You can enhance the security of your website using WPCLi. Users, administrators on your site will be able to edit themes and plugins and install themes and perform updates. If you don't want them doing that you can add this definition into your conflict file that disables that functionality. You can even set that through WPCLi itself with a WPConfit command. But the problem then is that you can't go into the admin area and you can't manage updates and plugins and themes. WPCLi though is unaffected by this command so if you continue to use WPCLi on a site where you've got disallowed file mods set to true you'll still be able to install languages, you'll be able to install plugins and themes, you'll even be able to perform updates because of the way WPCLi works it doesn't take into account this disallowed file mods constant. So it means you can lock down the admin area so your administrators aren't going to go in there and mess things up by running updates and installing new plugins but you can still manage those yourself through WPCLi this is a really powerful feature of WPCLi. Hands up if you ever had a word press click site that's got a blank screen on it because you've got a fatal php error and you can't log into the admin area you can't manage your users you can't do anything. WPCLi has got this really handy flag called skip plugins so you can run any command and attach the skip plugins flag to the end of it and it will skip the loading of those plugins either all of the plugins here or an individual plugin name or even themes although that doesn't make much sense and it will load wordpress and it will allow you to interact with wordpress without that plugin included on that particular request this is a really good way to get yourself out of this problem where you've got a fatal error on your site and you can't manage it so that's a good one to remember there's also a dash dash require flag this will allow you to include a php file before it loads wordpress and before it loads any commands that you run and typically you can use this to write a little bit of php code that maybe fixes whatever error you've run into run it once it will include that file then it will load wordpress and then hopefully you've fixed your problem and finally also you can one run WPCLi in debug mode with dash dash debug and that will show all of the php warnings and notices that otherwise get hidden by WPCLi so a good fourth exercise when you're starting to use WPCLi is what do you do repeatedly on your site that you should be able to automate have a think about it like the installation of wordpress to start with is a good one but user management is another one maybe there's things that you do repeatedly on your site you think ah it'd be great if I could automate this you should be able to automate it with WPCLi you can administer remote websites with WPCLi this is a really handy feature um if you've got a production website on a server and you normally ssh into the server and then perform some actions WPCLi has a concept called a this is and it's this app syntax here and in your configuration file for WPCLi you can set up path to files you can set up the ssh credentials every time you run this command with a app prod WPCLi behind the scenes will ssh into that server it will navigate to the directory specify it will run the command it will show you the output and then it will disconnect from ssh so does it all in one means you don't have to remember those ssh configurations every time you want to manage a remote site and it's handy also for local sites not just for ssh so for example um this is a site this is a path to a site on my local machine I can just access this with you know for example WPC at dev e-vifium I'm not in that directory when I'm managing it so these are areas this these are really useful uh how about converting a site to HTTPS HTTPS is becoming very important these days through SEO and performance and security you can easily convert your entire site to HTTPS with the WPC search replace command here we're switching from the HTTP protocol to HTTPS and what would what WPCLi will do is it goes through your entire database it will show you uh all of the fields that it's replaced but the key thing is that this is aware of serialized data so if you've got a plugin on your site maybe that is storing data in a serialized array WPCLi won't mess that up like you would if you did a regular search replace through MySQL so this is a really handy uh uh the command also if you just want to change your domain name to point somewhere else again WPC search replace this is one I found quite recently uh you can quickly connect to MySQL using the credentials that are in your WPConfig file so let's say you need to connect to MySQL to run a command but who remembers their MySQL username and password usually what you're going to do is you're going to go and find your WPConfig file find those credentials in there and paste them in the command line with this shortcut here called wpdbcli what it does is it reads those credentials straight out of your config file so you don't need to go and find them yourself and it just opens up a MySQL command line you can run your SQL commands and uh you haven't had to go and find those credentials here's a bit of a crazy one you can blog via the wpcli I wouldn't recommend it but you can uh wp post create um this is a command that will create a post but there's an interesting flag here called dash dash edit and again this opens up the editor that you've configured on your command line so you can type out the full contents of your posts and then when you save it and close your editor wpcli will save that as a post to the database and there's an equivalent as well wp post edit give it a post id and again open up the editor that you've configured so you can edit that post on the command line it's probably not something that you're going to do very often it's not going to replace Gutenberg anytime yet but it's there if you need it in an emergency maybe we'll have a Gutenberg block builder in wpcli one day and there's a really interesting page on the wpcli website called shell friends it's in the handbook uh if you just go on there and search for shell friends uh this page introduces you to a lot of the foundational um uh functionality of the command line that isn't specific to wpcli so for example interpolation here and piping these are all uh features of the command line that will help you use wpcli much more efficiently for example what we're doing here is we're running a command wp post list and fetching the id's and then we're passing it into wp post delete in order to delete a bunch of posts and here we're using piping to fetch a list of all the available languages and then automatically install them so if you want to set the multilingual site you can do that in one command so if you're not very familiar with a lot of the concepts of the command line this shell friends page on the wpcli website is a really useful one to get some tips and tricks on how to get started there so that's wp-cli.org i also started a newsletter called wpcli tips unfortunately i've neglected this a little bit over the summer i had a bit of an extended summer break but if you go to wp-cli.tips you can sign up and uh i'll start sending out a monthly email newsletter again with tips to use in wp-cli uh news on new features in wp-cli that kind of thing so you can sign up there and that's it from me thanks very much does anybody