 How many of you have ever played with desktop server? Yes. It's awesome. Let me introduce you to that brilliant gentleman, Mr. Steven. Thank you, Chris. Okay. Let's get started. Okay, so as you know, desktop server, if you're not familiar with it, it's a local host development tool, very similar to MAMP or WAMP, but we really optimized it for WordPress. So you can use a nice fancy GUI to create WordPress websites and do development on your local desktop, not having to pay a hosting provider. You create as many websites as you want and basically do all of your development online, offline rather, until you're ready to go staging online. But there's been a lot of talk about how the GUI almost kind of looks like a toy, right? It's just a little bit too easy. And today's topic is going to be top CLI recipes for WordPress development. And we're going to revisit the command line and why the command line is still important and relevant today. So we're going to start off with a couple of beginning commands if you're not very familiar with the command line. How many people here use the command line and know how to... How many people here are familiar with the command line but don't know how to change directories or manipulate the file system in the command line? You're beginners of the command line. Can you raise your hand? Okay, so it gives you a gauge as to how quickly I want to blow through just the beginning section. Then we'll move on to a little bit more advanced topics. So in the beginning, we're talking about the very beginning, like 1920. This is before computers in terms of transistors. There was a device called a teletype machine. And in 1920, the teletype machine was invented to communicate to other teletype machines. It's literally like a typewriter, just a step up above Morse code so that people could type on a keyboard and receive messages on another teletype machine and type back. But it wasn't until about the 1960s that the teletype machine came into play with computers. About the late 1950s, universities were bringing mainframes online. Computers, transistor-based computers and occupied huge rooms came online. And they found that the most appropriate way to communicate with them if you're across town is to retrofit the teletype machine to talk to that computer, whether it was at a university or at a big mainframe at some corporation. You could literally pick up the phone, slam down your receiver onto a teletype machine and type away. Now, the teletype machine in 1960 brought about the alphanumeric language or the alphanumeric set called ASCII. So how many people here are familiar with ASCII? Alright, awesome. So before you could have a computer language, you really needed to take a step back and have a computer alphabet. And so ASCII became the standard in 1960 for people to type on a teletype machine, send basic, which also came about in the 60s, to send commands over to the mainframe and get the results back. But the results didn't come back on a screen and, in fact, they didn't really come back on a typewriter. They came back in a punch card. You can see how these devices that you can see the punch card here and it allowed you to see the results of, say, basic commands that you could type in and then send to a machine and then have them come back. The punch card was kind of a precursor to the USB drive. Only it used a lot of trees, right? So it would definitely come a long way. But that notion that the teletype machine or the command line, if you will, is so dated really isn't true. Now the teletype machine itself was retired in 1984, I believe. Does anybody else know what came out about 1983-1984? The GUI. The GUI was born. In fact, the Apple Lisa was one of the first machines and then came the Apple Macintosh in 1984. MIT released X Windows, which is basically the window manager that was replicated in Windows. And it kind of started a little bit of a holy war as to whether or not the GUI or the command line was a way to go. Now the GUI is fantastic. We designed tools for WordPress developers that are very GUI centric because it really ushered in a whole slew of users to utilize the computer without having to know all these arcane commands on a command line. But Wired Magazine had an interesting quote and the quote is, the command line isn't a crusty old-fashioned way to interact with a computer made obsolete by GUIs, but rather a fantastically flexible and powerful way to perform tasks. I'm going to show you how there are some tasks that you can do with a command line that you still cannot do as efficiently or even at all using a GUI tool. And so another quote by co-founder of Unix, Rob Pike, he's actually a developer of the Go language, when people are using a particular system, say that the command line is better because it can do things that a GUI can't but you can't do it rather than a GUI, they're not talking about the strengths of the command line interface, but rather the shortcomings of the GUI. So now with modern systems, we have a number of choices between command lines. If you're a Windows user, you might be familiar with PowerShell. MS-DOS is a popular command line that was used in the early PCs. Then there's ZSH and Bash, and ZSH and Bash are very similar. Bash kind of does 80% of what ZSH does, but the Bash command line really has the longest history out of the four that are presented here. Bash stands for Born Again Shell. That's actually a rewrite of the original Unix command line, which was called Born Shell. So if we take a look at each of the different command line choices, like PowerShell at MS-DOS, it looks like the Bash is kind of reaching the de facto standard, if you will. And why is that important? Well, if you're a Windows user, and you've... How many people back up their WordPress website? I hope you guys all back up your WordPress websites, and you download an archive. I mean, how many people use caching? Like W3 total cache, super cache, right? So if you get this archive and you download it, and you happen to be a Windows user, and actually this can happen on Macintosh as well, sometimes you get this path too long trying to unzip that archive. And it's not actually limited to just the GUI. You can use an unzip utility from a third party like Winzip or Winrar to unarchive a zip file. This error happens because sometimes your backups contain these cache directories, or sometimes plugin authors develop on maybe a Linux system, but they don't need to take into account the Windows system where you have these really long file paths. Does anybody know what the limit is on the file paths on Windows? Did you say 8.3? That's MS-DOS, but... Yeah, yeah, that's 256. About that, that's about right. It's actually, I think, 248. So they take a couple of bytes for some other reasons. So if you encounter this, you can always go to the command line to try to take care of it. But unfortunately, you do have to be wise about which command line you choose. So here's an example on the command prompt in MS-DOS. We tried to unzip a file, but we still encountered that the text file's too long. I kind of went out of my way in this particular demonstration to show a really long file name, but it is an issue that happens, and it can happen to you, unfortunately. We're really hoping that PowerShell was going to correct for this issue, because PowerShell is the leading command line in the latest version of Windows 7, 8, 9, or 8 and 10. But you still do encounter this issue. And yeah, it's 248 characters for the file name, or rather for the directory, and I believe the file names are limited to 260 characters. So that can be a problem if you're trying to unzip files. But hell has frozen over. Bash, which is a command line in Unix and Linux systems, and the default command line that you actually find on Macintosh computers, is now coming to Windows. So the latest build, can we get an applaud? Microsoft is now including the Linux Bash command line in the next version of Windows. So you can actually activate it now. I believe you have a developer. You're part of the Amazon developer network. You can get ahold of it. I think someone had mentioned that it was free earlier. Yeah, so that's definitely coming. And it does not have that shortcoming. If you want to delete a file, again, you can use a third-party utility, like Winzip or Unzip. But then you have a problem unzipping that file and then trying to delete it. You can't get it off your desktop. But if you're in the Bash command line, you can. So we're going to go over some basic file operation side-by-side with the window manager to illustrate that. So Bash is the way to go. We're going to go into the fact-toe standard. And there are several ways you can get started with Bash. Well, if you're a Windows user, we always had this Sigwin project. It's really come a long way. Someone else had mentioned Shocklity earlier I was talking to. And that has come a long way as well. In fact, it's kind of... I think a lot of the development in Shocklity is going into the Windows 10 update. You're going to see where Bash becomes native to the Windows interface. And then there's desktop server. If you want to use a command line that doesn't happen to be a desktop server user, there's a new plugin that I wrote. And it's available on github.com, stevorivo.com. And that's going to give you a command line that's all primed and ready for WordPress development. What does that mean? It has WPCLI built into it. It has Composer. It has even Node and MPM package managers. It's basically ready for you to get down and dirty and do WordPress development on the command line. It's cross-platform. So you also have DSCLI available on desktop server for Macintosh. Even though Macintosh already has a native Bash command line interface, what the desktop server plugin is going to do is it's going to install a separate private version of Homebrew and basically spice it up. So you get WPCLI, you get Composer, you get split, you get a lot of these commands like W get, which is missing. If you have an existing Homebrew installation, it's not going to interfere with that. Likewise, it's true with SIGLIN. If you already have SIGLIN, you can still use desktop server with DSCLI. And then if you're a Linux user, how many Linux users do we have out there? All right, you guys are already awesome. So there you go. Okay. So I'm going to show an example of basically installing DSCLI because there are a number of choices you can go with the command line. Of course, if you're using Baygrant or you're using Map, you can pre-configure your command line interface, but this is definitely the easiest. So I'm going to go through this process of installing. And so it's distributed as a zip file on Macintosh. On Windows, we make it an executable because the tool itself contains a lot of long file names. And again, as I explained, it's not going to install correctly if we try to unzip it on Windows. There's a self-extracting executable. And once that downloads, you can see how easy it is to install. I'm going to how many Windows users do we have right now? All right, so we still got a good and good mix. Right on. So when you install the plugin, it's going to install into the... on Windows, it's going to be the XNAP Lite folder, DSPlugins folder. So the DSPlugins folder is basically a folder where you can install desktop server plugins. A desktop server plugin is just like a WordPress plugin. In fact, you can take a WordPress plugin and pop it into that folder. And now that plugin will be active in all of your WordPress development sites. Sometimes that's not appropriate, but it can be convenient. The desktop server plugin folder is primarily used for developer plugins. For instance, we've got a plugin out there that allows you to bypass login. You ever get an archive from a client. And what's the first thing that you do? You install it, but maybe they didn't give you credentials to login. So the bypass plugin bypass login plugin is a perfect WordPress plugin that you can install in the DSPlugins folder. It will become active in your development sites and you can login right away. Not something you want to deploy, right? At least I don't recommend it. But by keeping a separate DSPlugins folder, you're not having to deal with that across my place one second. So we've downloaded the plugin. Long video. Sorry, guys. Just a moment. So that's going to go ahead and do its installation. And it's going to be a little bit of a heavy plugin if you're a Windows user, because it is installing a lot of little tiny files. And those files are the command line utilities, like Split, like Wget. A lot of little binaries that basically make up the Linux operating system. When you install the desktop server for CLI plugin, you're basically installing SigWin, or portions of SigWin, along with WPCLi and what have you. And then once it's installed, you can fire up desktop server and you're going to get a new option. And those of you that haven't seen desktop server, you can see a demonstration of how we're going to create a WordPress website in under five minutes. The first thing to do is to start or stop the server and you're going to check to see what developer plugins you have installed. And there's a DSCLI plugin. We just check it off and click Next. What that's going to do is it's going to cycle the Apache server that desktop server uses and it's going to make sure that that plugin is available in all of your WordPress development websites. And so desktop server is going to create the database. It's going to configure your WPConfig file and I can show that here in just a second. So the default option is to create a new development website and I'm going to show you how the command line interface plays into this. So we can type in a testing development website name and choose the WordPress 4.5 and all the Apache logs or rather the Apache VHOS files are going to be configured for you. Your WPConfig is going to be configured for you. All the keys are going to be sorted and then we can start a new installation. So testing.dev is our fictitious domain name and we're just going to make a couple of websites here. This first one is going to be testing site. I'll put in the password and then email address. Now we can go ahead and log in. So when you have the desktop server CLI plugin activated within this development environment you're going to get the typical admin bar but you'll notice there's a DSCLI icon on the admin bar. If you click that you're going to get the command line pop up and I mentioned that it's using SIGWIN that's basically what you see here. Now this is a little bit different because the command line isn't going to start up in your home folder. It's going to automatically put you into the development website that you're working on. For instance testing.dev. Anybody know why? It's a prerequisite for WPCLI. You need to be in the document root of your WordPress website to use WPCLI. So before we get to WPCLI let's take a look at typical file system navigation. So we have a couple of users actually several users that said that they don't use the command line on a regular basis. So we're going to go through and blow through some simple commands like how to list files, how to change directories, etc. We're going to do that side by side with a window manager so that you can get kind of a general idea and see that the command line really isn't that scary. So on a window manager it seems like it's really forgiving why it because we have this trash bin that we can always undo operations. Well the command line is actually pretty forgiving as well. If you even mistyped something 9 out of 10 times you usually get a command not found. So it's not really that scary when you're typing on the command line. But what I'm doing here is I'm going to show you how to list files. Now when you open up the window manager you're usually placed in your home directory. Now on the command line when you open up a command line you're placed in the home directory as well but you just don't know it. There's a key command that you want to type which is ls to list files and that's going to show you the corresponding files like you would if you just opened up a document window. So if you want to go to the documents folder we're going to go ahead and type cd which stands for change directory. And all these commands are listed on my website so you can kind of use it as a chi chi to get familiar with the command line interface. And then on the gui you can see we're in the documents folder and there's a websites folder and that's typically where a desktop server stores its development websites. So if you click the websites folder you go into that the equivalent command again is cd and you can put that within quotes websites and then just press enter and it's going to pop this into the websites folder. And then just type ls again and you should be able to see the folders or the files that are there. Now to create a new folder you typically type right click or click on file in new folder and you create a new folder in gui. Now on the command line you're going to use make directory which is mkdr followed by the folder name you want to create and you can see there's a new folder there. So really simple on windows you can right click a folder to delete it then go ahead and select delete and on the command line we have a powerful command line operation called rn to remove and then it has these options and the options are filed by hyphen for rf to remove a directory and all of its subsequent children. So if that directory has any files in it they're going to get blasted too and so you can see now it's gone. So that covers changing directory listing files and removing directories. Now the command line typically comes with a built in editor called nano. A lot like edit on the old Microsoft windows and that's the OS command prompt. Anybody use edit? Am I dating myself there? No I'm not dating myself here with it. Nano is really really easy. A lot of people use another terminal editing program called or file editing program called di. I'm going to kind of stay away from that. It's a little bit more advanced but if you're familiar with edit or familiar with typical text editor nano is a way to go. It's available on all platforms and I'm just going to write it a quick hello world app and then press ctrl x to exit and it's going to go ahead and then press y and you'll see the file pop up in the window manager over there. So copying files. Now that you have a text file you want to be more comfortable in the command line. Copying is easy. Cp stands for copy. You type the file name and then the file name you want to copy to and there you go. So that's your crash course introduction to the command line. How to manipulate files in parallel with the manager which you're probably already familiar with. All commands on the command line they're really not that difficult. Once you get the basics down you can write scripts, you can automate processes but getting help is always a good question. There are several places you can get help on the command line. When you're in the bash command line typically you can always type man which stands for manual followed by the command and it's going to show you a manual on how to get help or manual on that command. In addition all commands usually have a hyphen hyphen help shortcut. So if you forget how to make a directory you can just type hyphen hyphen help and then up comes a quick cheat sheet of all sorts of options and then man is something else that I mentioned. It's going to give you a way more detailed breakdown. It's actually the user manual for mk how to make a directory. Okay. So now you guys know the basics. Let's get down into WordPress and see how WPCLI which is an enhancement of the command line is going to help you automate some processes. So the top WPCLI commands that we always get that we're always using in support to help users out is how to back up your work, how to roll back your work, import data and then how to do search and replace. So exporting your database. You've been working on your WordPress website at some point you're going to want to maybe try some new plugins out. Things can get really destructive we're down to five minutes already. You can type WPDB export and that's going to back up your database. Really a good idea before you try some new plugin so that you can recover your database if you need to. So that's an example. WPDB export is going to create a file called backup.sql and we can see it there. Okay. Search and replace. So if you have a number of URLs inside your WordPress website that you need to change maybe using a content development network and you forgot to update some URLs or in this case we just have a site title testing site so we want to replace that all over the place. We're going to use a WPCLI command to do search and replace and I'm going to type WP search and replace, testing site followed by say computer history is a new title. So everywhere in my WordPress website because a WordPress website is not a text file you can't really do search and replace. WPCLI has a search and replace tool that will make that really easy for you. So if I hit refresh on the web browser we're going to see that changes to computer history. So anywhere within that website that string gets replaced globally. Okay and then restoring the websites just as easy it's going to be WPCLI import and we can restore the website. So I wanted to jump into because we're running out of time here PHP unit testing. How many people here use PHP unit testing now? Okay. So you can get started with PHP unit testing using DSCLI. It has PHP unit testing built into it. In fact there is a blueprint for desktop server. It's available at github.com and it's called the WordPress PHP unit testing blueprint. You can use that in desktop server or you can unpack it and you'll see WordPress in there the ability to get WordPress plus all the core files to do PHP unit testing. So I'm going to create a new website based on WordPress and PHP unit testing. I'm just going to skip ahead and install WordPress. So create a new development site called PHP testing.dev based on that blueprint and when I log into the admin screen we're going to get that DSCLI prompt there. If I click that I can now type PHP unit test on the command line and it's going to run through any unit tests that I've set up and this is going to be a quick template for you to start testing your own plugins. We're going to see it fail here. So if you download the PHP the WordPress PHP blueprint you'll have a blueprint ready for testing your plugins and your themes. In fact I'm going to go ahead and create an example test here. So it's going to be like a typical WordPress website where you're going to have a testing directory next to your WP content and your other WordPress files and there's two files in that testing folder. The bootstrap file and the test sample file. So if you look at the bootstrap sample file you can list any themes that you want to start testing under PHP unit and you can also list a number of plugins that you want to start testing. So what I did was I created a little framework there. You can add your theme like 2015 and then we're going to change the hello.php that's going to be our plugin that we're going to test because WordPress comes with hello.dolly and now if we go ahead and run and edit our text sample file you can go in and create a number of tests and this framework here is going to allow you to create a couple of unit tests. In this case we're going to test for the 2015 version 1.5 so say we're doing some testing we're making some modifications and our core theme needs to be say 2015 1.5 we can create a unit test for that and then lastly let's say we want to test hello.dolly make sure that it's activated. So there's the assert true and we're going to make sure that hello.php is true and that will tell us whether or not the theme is actually activated now when we type PHP unit test ok hopefully you'll see our test pass and there you go so we've tested the hello.dolly plugin we've tested whether or not we're actually running the 2015 theme so to get started with PHP unit testing like in desktop server you can go to github.com stevorivo.com and then you can drop that that blueprint into desktop server if you're not using desktop server there is a blueprint PHP file you can take that PHP file and you just need to execute it with the PHP command on the command line so PHP that will go ahead and go out to wordpress.org get the latest version of wordpress it'll go out to the subversion repo and download all the testing units that are a part of the wordpress core that the developer team put together and then you can start doing testing right away on your desktop and then lastly you can create as many testing websites as you'd like ok so that does it for PHP unit testing I went ahead and put together a couple of links that we talked about about getting general help bash stackflow.com is a great place to get help if you're not familiar with the bash command line and the manual and the online dash dash help trick doesn't quite work for you plenty of examples there the desktop server CLI plugin is available on github by username stevorivo and then under for PHP unit testing you got the blueprint wordpress-php unit ready to go and then last but not least the make.wordpress.org website to actually look at the official handbook on testing with wordpress and PHP unit ok and that's it for intro to the CLI and how to do PHP unit testing and how to manipulate the interface if you have any questions you can always email me directly you can hit me up on twitter does anybody have any questions I think we're yes no you definitely don't want to do that so as I mentioned the command line is really forgiving if you do do have a typo you don't have a recycle bin but 9 out of 10 times you do get the command not found so yeah but that's pretty much you really can't be afraid of the command line it's not going away it's going to be there for a while question so there's a 3.9 that's coming I can tell you that much yeah so we're making a transition to 4.0 and this is all the process the command line interface that functions on windows delivering bash to windows is really huge major needs to be vetted there's lots of projects that are doing it but we wanted to choose the right project so the DSC LI plug-in is a precursor to that yeah okay I think we're done yeah so steederrevo.com shortly after this presentation you'll be able to find them on my website alright