 Hello everybody welcome to track one of World Camp Lisbon 23 on the afternoon So thanks for waiting for some minutes We are delaying the beginning of each talk and this first part of the afternoon for 15 minutes because you know The lunch was served a little later. I hope we We as organizing team hope we have a great lunch and please forgive the Delay it was somewhat unexpected, but sometimes this kind of situations happens so welcome and Be ready because we have 15 minutes delayed, but we will go full speed ahead until the coffee break the coffee break will be shorter 15 minutes shorter So we can line up for the rest of the afternoon And now ladies and gentlemen, this is my huge pleasure to welcome Milana cup to World Camp Lisbon Milana is a WordPress engineer. She works for XWP as Developer and works also for the documentation team for words press.org and she let five major or four major Releases related to documentation with focus on the New Issues related to the programming for the WordPress project. She also helped to organize several conference WordPress conferences including World Camp Europe 2018 and 19 she is a single man. That is a super power that she has to Run against all odds in a lot of things but she has a weak point two weak points first you can bribe her with chocolate dark chocolate and even better a really nice Piece of bacon And be ready because in the next minute we will run to the terminal and We will learn a lot of things that we can do in five minutes in WP CLI But please hang Because this is live be ready Milana cup Hi, thank you So I have to cut this talk But I will give you something very special that I've never done in this talk before So there is a Kind of In the beginning I Try to explain you why WP CLI is very good for you And we will cut that now because you are here you want to learn about it WP CLI is command line interface for WordPress and today we have so many CLI tools and I'm very happy for that And you should use them all the time. Why? if we compare WP CLI and WordPress which is kind of Graphic user interface right for WP CLI. It's WordPress. So when you compare it what you can do in WP CLI and WordPress dashboard, there is this first level of using WP CLI you can do everything the same as You would in WordPress dashboard anything that you can do in WordPress dashboard fresh install You can do with WP CLI and this first level of using WP CLI I like to call Guilfoy level and that's if you want to just play and test around then you want to do more You want to list Chrome jobs? Everybody does it's okay. So you In dashboard you cannot do that without a plug-in or you cannot export or import database without a plug-in, right? With WP CLI you can do that on French is still no plug-ins needed and that second level of using WP CLI is But then you want to do more right? You might want to export just parts of database. I needed to export just a part of Database just post in last six months. I didn't need all the team options all the authors or whatever I just needed that with WP CLI You can do it without any plug-in with dashboard You can't do it and this level of using WP CLI is Neo and now you think there's no more levels. Well, there is You might want to Create your own custom WP CLI command you might want to create a plug-in There is no plug-in for creating plug-in and we don't need it, right? We have WP CLI and some very smart hosting companies and plug-in authors have been doing this creating Custom WP CLI commands for years now now imagine you get a new Project you log into your hosting and you dig a little bit and oh my god There is SSH access, but then you dig a little bit more and you see there is WP CLI available No, you're flirting stop it, but then you see There are Custom WP CLI commands for you to do things faster in their own servers now that New level of using WP CLI is mr. Robot level So now I managed to in less than four minutes to convince you you want to use it Of course you do I'm gonna show you can we switch to this are we switched Sorry So I don't have any server or computer without it. I cannot show you how to install it, but it's quite clear with the Documentation sorry, no caps lock all you need is three and a half commands and With this first command You just Downloaded and it's already working. So basically you just need this one command But then there is this half command that you want to check it if it's working It's working, but you don't want to type PHP WP CLI every time you want to run command, right? Nobody wants that. So what you do is you make it executable. This is the second and a half command and then you want to move it somewhere in your path and Execute it from anywhere you like. This is the most common thing how it's called WP And whatever you call it here, that will be the command you start commanding with You can call it whatever you want as I said, but just keep in mind once you install it You will do a lot of copy pasting from stack overflow Documentation so maybe, you know, it's saying to just call it WP and now we can go back and use it This is how it looks like No, let's do info and Here it is you have info about your system and everything that's there and A helpful tip when you start using WPC alive is Every command is trying to be consistent and there is anatomy of a command. So we have WP and then we have none This is entity you want to work with and there are a lot of entities And please keep in mind at any moment you can use help and list all of it So everything is there in your terminal. You don't need to go to documentation after none There are verbs that you can do with this none And you will find a lot of verbs are the same for commands like add create remove list Generate and we will see more of them. And if this is not Enough refined for you. You can use flags now flags is what would be arguments in a function or parameters so you can really really refine this for your need and at any time you can use global parameters One of them is help, but also there is one the most beautiful global parameter in the world And I'm speaking this specially for my friends from Laravel community Yeah, there is a prompt and you will see how powerful it is. So Now when we know how to use it, I'm going to talk about a little bit of administration Imagine scenario You had a client a few years ago. They never wrote never, you know, call you and now they send you email and they say that They cannot access their admin URL it keeps sending them to 404 page and They try WP admin they try login that read everything. It just doesn't happen And this is because you were smart and you change the login URL to increase the security of the website And you can tell your client to change it again so that even you don't know it and Let's pretend they did so now nobody in the world knows this login URL and you have two options You can go to Database and search if you have access which is boring or you can run one WPC like command And of course we live in a perfect world where every server has WPC like right available And we have SSH access so you want to do the second option and I'm with you there so we we can do SSH and Milana at That this is my imaginary client five five six five six no, sorry This is what happens This is port number And we are there and this is all great, but you're forgetting one thing. I Haven't heard from this client for years. I don't know that port number I don't know where's the file where I save that port number. I don't even know if I still have that file so What can I do with WPC ally? Well, I can use alias and I can even create aliases for groups of website if I want to do things in bulk I just don't go too much there. Trust me So how do I see if I have alias for this client? I can say WPC ally alias list now you see here WPC ally so the None is the third word here. This is because this is alias is Configuration for your computer. It really doesn't have anything to do with WordPress website that you have on your computer So if I list them you will see here. This is what I typed This is my client and my aliases at client. Okay so What can I do? I can say WP? Client, this is how you use alias. So WP alias name and then command as you would and let's say core version it has to be correctly typed to work and Oh It's outdated. So while we are there. I can just say core update Look ma no hands. I Didn't even go there. I suggest you do go there Just to check is if everything is as it should Okay, nice internet is working tell everybody else Okay, so what we want to do is find out the log in your app. So how can I do that? I can type WP client and Then I'm gonna use command that I've used too many times to Admit how many times so it's evil and it will Execute arbitrary PHP on your server. So you know that I'm not on my server. I'm just connecting through SSH via this alias, so I Happen to know let me put okay. I happen to know what is the function WP function for Getting login URL and it's getting login URL and I'm just gonna add here New line. Don't worry about that just to print it nicely And you should have asked Milena so This is my imaginary clients website now this task in real life could last for hours like you send them email. Oh, I don't have the Credentials and they say, oh, I don't have either and then you try to search for it on your computer but you cannot log two hours searching for password, right and Yeah, so this could be Very long Unpaid work that is frustrating Or you could start using aliases right now for every website you you have and in two years You will love yourself because your WPC like config file will be your All your credentials that you need and you don't even have to go and look because you have aliases to work with Okay, so I have eight minutes Let's see what I want to do I want to show you Something about security I have local website here It's Freshly installed WordPress and let me list users for you See admin admin and this admin is administrator. So Let's see what this admin can do WP admin command will take you to dashboard But only in your local because it behaves differently with Remote servers, but it's also a very good command that can help you Never to memorize anything if you didn't notice I don't memorize thing at all so this is my local website and I'm going to show you things that are Pretty obvious Not because I think you don't know them But because I want to make a point So this is admin and they have a complete access to post category stacks pages Appearance all the teams editor Site editor. There is plugin their tools. There is a team file editor and plugin file editor in 2023 You can edit PHP files from dashboard That's insane now When you freshly install WordPress, there is this Hello world post that is automatically created and published and default team always show the Username of this only administrator that has access to editing PHP files in your dashboard So what we need now is just a password, right? And WordPress websites gets hacked a lot That's not a secret and I like to think that's because we are popular But you don't want to measure our popularity with your client's website, right? So what we can do is we can Limit access to this Administrator and we are just going to say wp user remove capability Administrator No This parameter here the last parameter. I'm sorry. I'm just hurrying to to show you everything So the last parameter here should be either user id or email or username And I happen to know it's one Because it's the only one Remove roll. Sorry. I want to remove roll Right and now if we Check user list, you see the roll here is empty and what that means for this A user when they try to go to dashboard Nothing happens because WordPress has no idea what to do with you when you have no roll And now this WordPress is locked down and the way I love it But if you have a client they would want to have access to it, right? so we can do Create a new user wp user create and Now there are parameters that I don't want to remember I don't memorize things and we are going to use this the most beautiful global parameter in the world prompt And it will prompt you with every parameter there is so I'm going to say this is author and email it doesn't really matter Because we are in local roll. I'm going to say author Password this should be strong, but bear with me. I have to log in with that And just like on windows next next next I don't care. Yeah, so if I go back here and log out and log in with author Oh, we have very very limited access. This author cannot do Almost nothing and you can add more capabilities to this user wp user Add capability and now again the parameter is username or user id or Email I'm going to say to because I know it's too and I can say manage categories categories And this author now can Sorry Now have access to categories and tags and you can add a lot of capabilities just to you know Fine tune that access so everything dangerous is out of reach and they can really like Own the website but not break it because that's our job to break the website. Okay and It's important that you see here this I can't I don't have access to plugins to anything here and the other user has no access at all to This WordPress so keep that in mind and now we are going to do some magic. I have to go to my magic Uh folder. It's completely empty and I'm going to say wp install and it's doing magic We have less than two minutes. Come on database name is magic, of course my root I don't need this Next next next title is magic HTTP Magic dot lock admin It's cooking Coming up It's there hurry. Yes. Do you want to release the kraken? I think we want to release the kraken we came this far and It's the kraken And this is our new website made uh in WordPress. So it's not a magic It's actually just a bash script. So I'm going to say I'm going to show you this bash script I'm trying to do things very fast here. Sorry Wp install And you see this is very simple bash script it has download core and then it Creates a config so you have to create config file and I'm using this really really simple bash scripting to collect You know My username and to collect my securely collect my password because you don't want your password in bash history and then I'm creating I'm installing and rewriting structure because Here in this previous WordPress We have six seconds You see this index.php. I don't have that here because I use this rewrite Rule and then we have some Linux fun and then we open admin if we want to Release the kraken and it's very simple and let me show you now I'm going to show you this little thing that I Haven't done anywhere else If you want to create bash script you can do it very easily just saying history and minus a This is just in this session what all the commands that I typed and I'm going to say just you know test whatever and Let me open it sublime test This is file and you see this these are all commands that I have used so you can now easily just do this This is she bang and you say bin and bash And now you have your uh bash script and what you want to do with it here is you want to Make it You want to make it executable There is plus x test Now when I show it to you You see it's green. It's executable and After that I'm gonna move it to My path so move test to Bin test Okay, the point is I made a mistake and we are out of time The point is to move it to your Path like we did with wpcli when we downloaded and then you can Execute it from anywhere you want. So that's how easy it is to create a bash script and then you can fine tune it and Um My name is Milana top I am warpress engineer at xwp and the loudest member of the warpress documentation team I'm also classical musician if you want to talk to anything About anything to me just uh, you know find me there and I want to thank these wonderful organizers for Everything they did and I want to thank you for your time. Thank you Thanks Milana. It was a fast pace In next in the last mile so thank you and Now to show our appreciation to you It's uh tile from portugal. We hope you enjoy Folks we don't have uh