 All right, before I, can you hear me with this thing on? Okay. All right, so before I get started, this is kind of a beginner kind of level talk, so if you've developed plugins before, you've kind of done this, you're probably not going to get a whole ton out of it, but you're welcome to stay if you want. But I wouldn't be offended if you were to duck out, either. So a little bit about me, they talked a little bit. I do have 14 plugins on WordPress.org. I've contributed to WordPress core, so if your website is updated to 4.9 or higher, which it probably should be, my code is already on your site. But my background is not as a developer in software development or anything like that. I have a degree in accounting. I was a soldier. I taught myself how to code, and I guess the reason why I'm saying all that is because if you don't have that background, a development background or whatever, you can do it, too. You can learn I don't have any special superpowers that taught me how to do this. All right, so what is a plugin? Plugins are really just software that makes, that changes how WordPress works. They're usually written in PHP code, but other code can be used, too, like JavaScript and other languages can be used, too. Plugins make it easy to add new features to your site. Out of the box, WordPress doesn't really have all the features that you might need. So, for example, like contact forms and your page builders or e-commerce or SEO type stuff, WordPress doesn't have all that stuff necessarily baked into it. There's a myth, kind of, that plugins will slow down your site. Plugins aren't inherently bad or slow for having on your site. It's not a bad thing to have a plugin. However, some tech support type people have perpetuated this myth by saying, oh, you just have too many plugins when there's something wrong with your site. I kind of feel it's sort of a lazy way of saying that there's a lot of plugins on your site, and we don't really want to look through each one individually, and so just start taking some of them off and hopefully one of them magically fixes things for you. Some of the plugins that are out there actually will speed up your site. There's caching plugins, there's plugins that will optimize images and stuff like that, so they're not inherently bad. They won't inherently slow down your site. However, badly coded plugins can slow down your site and could cause some issues. I also want to make sure everyone's kind of engaged with what a theme is versus what a plugin is. Themes are kind of... think of a car. So themes are kind of like the exterior of your car. The color of the car, the shape, the type of car, whether it's convertible or an SUV or a minivan or something like that. So themes control the look of your site, what everything kind of looks like. And it manages the appearance of the site's header, the footer, the sidebars, all the content area, stuff like that. On the other hand, plugins are, if we're using that car analogy, plugins are the interior part of the car. Your engine, your GPS system, it has heated seats, things like that. Plugins control the functionality, how the site works, what it does. While themes control the placement of the different content on the site, plugins will have the ability to create new types of content or modify the existing content. Think about products like in an e-commerce store, for example, that wouldn't exist necessarily on a default WordPress site without a plugin to add it there. So plugins basically will add features that don't come with WordPress. So why might your site need a plugin? A plain install of WordPress can be pretty limited. And don't get me wrong, it's 100% all you need if you're going to run a simple kind of website, maybe a basic business brochure-style website or if you want to start a blog or something like that. You don't need any plugins to do any of those types of things. But the power of WordPress is in its extendability, how flexible it can be. And it's really simple to add plugins for SEO, e-commerce, contact forms, connecting to third-party services and about 54,000 other things that are available on WordPress.org. Or you can even code your own plugin as we're going to talk about a little bit later. So a lot of times people will want to do something on their site, they want to change how something works or add some functionality, and so they'll do a Google search and find a bit of code online that says copy this code and put it into your themesfunctions.php. And that's fine, it'll work. It's functional. But there are some dangers to doing that, adding stuff to your functions.php, which can be alleviated by having your own custom plugin. So... And actually sometimes the functions.php file is the appropriate place for some of this code, but it's not always. So, for example, if you have theme updates, if you added some code to your themesfunctions.php file, and your theme gets an update, when that theme gets updated, all of that custom code that you added in is going to get wiped out. It's going to be replaced. So your existing functions.php file will be on your server, and then the new theme update will come in and just put a new version of that in. You can completely lose whatever you had. One way to fix that is to have a child theme. If you're not familiar with what a child theme is, you can look it up. I'm not going to go into what that is right now, but just real quickly, it's a... basically a... almost a clone of the existing theme that you have, and it just is a place for you to make your changes and it'll never get updated so that those changes won't go away. That's a good place to put some of the code. But there's another problem with that. Let's say you go and make a couple changes to your code and then you decide, you know what, a year from now, I don't want to use the same theme anymore. I want to change it. So you go and you find a new theme, looks all nice and pretty, you put it in, and then you're like, well, what happened to all that custom functionality that I had? Maybe it was adding a new something to your site. Well, it's going to be gone because you've taken off the old theme that had your custom code and you're using a different theme, and it's going to be gone. It might be okay if the custom code is doing something that's specific to your theme, that maybe it's changing how the header looks or the sidebars, or it's doing something that's specific to your theme, that might be just fine. However, if it's some sort of functionality that you want to continue on your site for forever, you probably should end up putting it in a custom plugin. So that's kind of what we're going to talk a little bit about today is how to do that. So benefit of having a custom plugin is that the code that you put in is not going to be like we talked about. It's not going to be lost with a theme update or changing themes or anything like that. You're free to do that. You're free to change your theme whenever you want. I also think it's easier to troubleshoot issues that you might have in the plugin. It's not going to be lost with the code or whatever. It's easier to troubleshoot this stuff because it's just as easy as clicking deactivate in the back end of your site, and all of that custom code is not going to be run on your site anymore. And so if you click deactivate and all of a sudden that problem that you're having goes away, well, now you can probably pinpoint the problem to be somewhere in that custom plugin that you've written. For example, if a short code is going to add some content to your page and that page is starting to act funny or it has some errors on it only when that short code is in it, you know that that short code plugin has something that's messed up going on it. So you can either fix it or just disable it for the time being until you figure out what's going on. There are some popular contact form plugins that are out there or a lot of different plugins that are out there that have they don't bake all the functionality that they could possibly have into one single plugin. And the nice thing about that is you don't have all this extra code running on your site but also if there's ever a problem with one of the specific functions that one of their add-on plugins put on your site it's pretty easy to troubleshoot that. You just deactivate it and then you can kind of figure out that yeah, okay, that plugin was causing this problem. And so with that code separated into the multiple different plugins it kind of makes a little bit easier to troubleshoot the issue. Now let's say you've gone around and you've decided okay, I want to put my code into some custom plugin. How do I do that? So things that you're going to need are first thing you're going to need is some sort of text editor. Any plain text editor will work. You don't want to use something like Microsoft Word or a word processing type program. Those just won't work. Built-in text editors on like a Windows or a Mac computer will work, but they're also not really built for this specific purpose. There's free and open source options available. I have on the slide here that are just fine to use. There's also other paid and non-open source options that are available. Personally I use sublime text. I'm not going to get into the details of the benefits of one over another. Any decent one though is going to have some sort of code highlighting that will help you troubleshoot the errors as you're writing them. Whether you forgot to close a parentheses or you forgot to add a semicolon or some other something in your code might have gone wrong. That code highlighting will kind of show you those errors as you go through. It's also good to, if you're doing stuff on a remote server it's good to have like an FTP program where you can log into that remote server to upload your changes to the server. I say that because sometimes you can use in WordPress there is a editor where you can edit the plugins files. I don't recommend doing that because if you do make a mistake and then you click save you could cause the whole site to just be a white screen and then you have no real way to go back and change, revert those changes back to what it was. If you're using an FTP program you can save the original copy of your plugin file somewhere on your computer. Go ahead and make your changes. Upload it to the server. If you see that there's problems with it you have a backup of it. You can re-upload that and it's going to kind of alleviate any of those problems really quickly. But definitely make sure you have some sort of backup of whatever it is that you're working on. Whether it's just copying your computer or if you have a GitHub or something like that you can use to backup this stuff and you can revert those changes pretty easily. Also I know I was saying use an FTP account to upload files to your server but use a development site of some sort. This will prevent your live site from crashing if something goes wrong. If you add some code that doesn't quite work out on your site. Like I said before, if you're editing PHP and you miss like one comma or a quote or a semicolon or something like that it can just bring the whole site down. Many web hosts and a lot of them will have some sort of staging or development environment where you can basically take an exact copy of your live website and they'll copy that over. Then you can go and make whatever changes you want and it's not going to affect your live site right away. You go and make those changes and once you're happy with it everything is working the way you want it then you can copy those changes back over to your live site and it's not going to hurt anything on the live site. If your host doesn't have that and you don't want to switch to a host that does have it you can install a server locally on your computer. There's a ton of options out there. I won't get into all of the different options that there are out there but there are a bunch out there we can talk about it later. Or another option is to just get a cheap hosting account that you want to use for a few dollars a month to kind of copy your existing site over onto that site and then you can make changes there. And again that won't affect your live site necessarily. Okay so best practice is when you're developing a plugin or doing anything with a code on your site a good thing to do is in your the wp config file in your site's root directory there's a line that looks kind of like up there, define wp underscore debug and by default it'll say false, comma false if you set that to true it'll allow any errors that are going to pop up to show up on your on your site as you're going along and developing. So that can help you identify problems before they pop up. So it's a good thing to set that to true. I don't suggest using that on a live site though only on your development environment. The reason why is if there are any errors whether it's from your plugin or some other plugin that you're using on your site causing some sort of errors it could identify these security vulnerabilities to other whether it's someone who wants to maybe do something bad on your site. So that could be a bad thing to have. So set that to false on your live site, true on your development site. Follow WordPress coding standards. There are two links here, the codex.wordpress.org and developer.wordpress.org have a ton of information on how to code kind of the WordPress way. There's a bunch of built-in functions so that way you don't have to go and reinvent the wheel on how to do certain checks or how to get certain information from the database. So if you're using their functions things are going to go a whole lot smoother. And finally use prefixes. If you in your code and we'll get to the code in a little bit in your code if you prefix your functions and all of your any of the variables and things like that it will help prevent conflicts with other plugins. So if you were to give your a function in your plugin a generic name like add short code for example that function is already being used someplace else. That's already used in WordPress and it's going to cause big errors all over the place. But if you add a unique prefix to your function that will help eliminate any of those errors. So you can use your plugin name or an abbreviation of your plugin name as a prefix and then whatever it is that you want chances are no one else is using that and it's not going to cause those conflicts between your function and somebody else's function. So we're going to go through a custom plugin that I've made for this purpose to use as a demonstration example here. So what this plugin is going to do it's going to create custom post types and I have a link to the documentation on custom post types there and it will also create a short code and again another link to the documentation on short codes. So custom post types before I go any further if you're unfamiliar with what a custom post type is WordPress comes with five default custom post types. They're post attachment revision and menu. Custom post types will handle specific types of content that you don't necessarily want to mix in with the rest of your content. For example an e-commerce site might have a products custom post type an education based website might have like an assignments custom post type. Movie review sites might have like a movies and actors as two separate custom post types. So think about it this way a post type is a default post type that's going to be on any site no matter what and that's where your blog post are going to show up. But not all content is a blog post and you don't necessarily want all that content to show up in the same place. You wouldn't want your blog post to show up every time you upload an image and because images are an attachment post type just like you wouldn't want every product to show up on your blog feed every time you added a new product to your e-commerce site. In short codes if you're unfamiliar with short codes they're a way to provide a way to dynamically insert content into your site. So by placing this little short code your site can run a function that will insert certain information into the site. You can't put PHP code into the poster page editor for security reasons but you can put a short code in there and so that short code can then go and run PHP code on its own. It can pull data from your site's database or it can even add data from another site using their API or things like that. Right. So if you are following along I see a lot of people have their laptops out and stuff. I have a actually if you can move the picture in picture for the link here I have a link here to the plugin that I coded for this so you can kind of follow along on GitHub if you have that. You can download it too and you can mess around with it. You can make changes you can do whatever you want with it. So that's out there for you to grab. So every plugin should have a few things. First thing is in your plugins directory you should have a folder for your plugin. All the files that go into your plugin. Technically it's not needed but it's very useful for organizing all your plugins files especially if there's going to be more than one file. Your plugin should also have a PHP file with a header comment and I'll show you what that looks like in a little bit. But in the header comment it has at a minimum it should have a plugin name and that name should be unique. Another plugin on your site sorry not on your site another plugin on WordPress.org if it has the same name for example if you called your plugin WooCommerce and obviously there's another WooCommerce on WordPress.org if their version number is higher than whatever your version number is you're going to get that update prompt on your site and when you click update on your version of WooCommerce it's going to just replace it with real WooCommerce and that's just something that should be avoided. So give your plugin a unique name. Your plugin header comment can also optionally contain a few other things a URL so like to the home page of your plugin if you don't if you have a place to put that description is a short description that shows on the plugins page in your WordPress admin the author's name a link to the author's website and if these things are like a custom plugin that you're not going to be distributing out anywhere you probably don't need a lot of this stuff you know license information and stuff like that you probably don't need too much if you are only going to use this on your own website alright so let me get out of here and pull up okay so this is the my plugins file the main plugin file make this a little bit bigger can you read this or should I make it bigger okay so my this is my WordPress site so it has our WP content our plugins directory and then I have my plugins folder right here Workamp Phoenix 2018 folder here with that I have a whole bunch of different files here our main plugin file is Workamp Phoenix 2018 .php and so the header comment is really really the main thing that is actually required if I was to delete everything else out of here this still would technically be a functioning plugin and it still could work let me go over to here so right now you see Workamp Phoenix 2018 plugin demo creates a custom post type and shortcode and all that other information if I was to get rid of all of this and save it and refresh so it would still technically be able to be activated and everything like that it wouldn't do much it just puts an extra line there so it's very useful to have all this other information so all of this down here basically pulls in all of our custom code that we want to use so in this plugin I'm adding a custom post type which has a whole bunch of different stuff in here in the code itself I added a bunch of comments so if you're looking at it on your own you'll be able to kind of follow along what it's doing but this code basically creates the custom post type using the WordPress built-in function register post type so it'll create a post type sports product and in this case what we're trying to do is what we're trying to do is create a way to add products to our WordPress site that will show up on the bottom of our pretend sports blog for this demonstration so I'm going to activate that plugin and I have so you can see now I have my new custom post type sports products and that's what I showed over here in the code that creates this custom post type so I go over to sports products I already added a few because I didn't want to have to have you guys go through all that stuff but basically all it does is it creates a way for us to call a product name and then add a link to our product the benefit of that is so that now I can create a a short code and again I have a bunch of comments in here so if you're following along you can read all about it but the short code will basically allow me to say I want to show all of the sports products in a certain category so golf or yoga or baseball or whatever it happens to be so if I'm on my posts I have just a generic golf post here and I have this short code so this tells me I'm using this the short code you can see apparently let's see if I can bring this up a bit there we go so I have this short code down here for sports products and what it does is it creates a an attribute called golf because I have a golf post that I'm writing here what that will do the way the short code is written is it's going to look through all of the post types that are the sports product that I had already created and it's going to look for and it's going to try to do a match on anything that was categorized as a the sport that I specify in the short code and when it does, if it finds anything what it's going to do is it's going to add this little section of code to the bottom of our post or wherever I put the short code and so in this case if I go and view my post you'll see we have our golf post here with all of our information and then it lists out all the products that I tagged as a golf related product and you can do that for any number of different categories so if you have like I said yoga or baseball or football or soccer you can continue to build on to that without really having to add any extra code and the nice thing about that is it's almost a set it and forget it kind of thing once you have all this kind of set up how am I doing on time okay so I've got a few minutes alright so I have one other thing here that I wanted to show and I know I didn't really get into the code too much and it's kind of hard to really dive into all of the code right now and your custom plugin isn't going to do what my custom plugin is doing your custom plugin is going to do the thing that you need it to do one thing I need to also make sure you guys are aware of is any PHP file that you're going to have so basically it ends in .php like all these files up here have they're all going to start with the code that's up here but you're going to open it with this PHP code when you go to other websites that have code examples you might want to might be tempted to copy and paste that into your site so for example I have one of my own examples here and I'm just going to copy this whole entire code example I'm going to copy that and paste it into my plugin file it's not going to do exactly what I want it to do it's actually going to break everything and it's kind of for demonstration purposes so if I go and add that excuse me if I go and add this code 100% the way it was on this site when I save it I'm going to come back to this site here and you see I got a whole bunch of errors that's obviously a problem but one of the biggest errors and error is because I included this opening PHP code again without closing it first so if I was to close it first and then do other stuff and then I want to open it back up again that would work just fine if I go back to my site and refresh the site will work just fine it won't have all those errors so as you're going along online and you're finding another thing that you want it to do just be sure that you're careful about where you're pasting your code where you're copying and pasting it into in your custom plugin make sure that you don't include the opening PHP line if it's already included and not closed so it's kind of a matching thing so you don't necessarily have to close it ever so if I was to download all of this that I have it opened at the top but I don't have it closed and that's okay I don't have to close it but if I'm going to add in another new opening one the first one that opened has to have a closing one and that goes for a lot of things in PHP code I'd highly recommend checking out PHP tutorials if you're going to get into this there's books there's probably college classes community college and things like that that you might be able to learn from so especially if you're finding yourself running into a lot of errors you might want to figure out what you're really supposed to be doing with all of that code that's just a common thing that I've seen happen a lot where people have copied and pasted stuff into their code and they just didn't realize that the closing opening and closing of those PHP tags was an issue but the same thing goes for like I have an opening curly bracket and I have a closing one here if I was to delete that and save and then refresh my page I'm going to have more errors so a lot of times it's just troubleshooting where did I forget to add the closing whatever it could be a parentheses even could be something as simple as a quote like that and we'll still have errors so as you're going through and coding your custom plugin make sure that you are testing it on a development site so that way if you do have those errors like I was showing before like this if you have errors like that obviously your live site especially if you use to run your business you obviously don't want your customers coming and seeing that kind of error so do it on a development site you're going to make errors I do it all the time I look at this and I try to figure out what I did wrong but I don't want that to happen on my live site I think that's about all the time I have if there's any questions I don't think we have time for questions here but I'll go head over to the happiness bar which is out kind of in the lobby area if anyone has questions I'll hang out there for a little while and we can chat then