 Thank you everybody. All right, so today I'm going to talk about off-grid plugins updates outside of wordpress.org Which may not fully explain what I'm really trying to explain I feel like a better title would have been you know that thing when plugins update you get that little notification To update the plug-in like that little update link, but like what if your plug-in isn't in the WordPress plug-ins? directory on wordpress.org and you just like make your own plug-in as just a zip file But you still want to update it have a little update link. This talk is about how to do that So a little bit about me I am indeed the Co-founder and grand-puba of technology at neutrino Inc. I feel my title is self-descriptive and For the last 12 years we have been making custom very fancy luxury real estate websites I personally have been slinging PHP and doing web stuff professionally since about 2002 so pre WordPress days and I Yeah, we do use wordpress to build these fancy real estate sites and I want to let you know all up front that all of the slides and all of the files it will be going through will be available online after this session and I mean going through a lot of code I mean going through a lot of it very quickly because I have way more to talk about than I can in 40 minutes So if you're seeing stuff up here that doesn't make a lot of sense Everyone you know has different coding abilities or or what have you? Don't worry about it. It's really not about the specifics I really want to give you the tools to be able to do this thing if it's something you're interested in doing and Why you might want to do this and if you want to really get in those details all the files will be available You can always come up and ask me later tonight of the after-party. I'll be here all day tomorrow hashtag both days and So so let's get cooking now. I mentioned this real estate stuff So we have our situation is that a few years ago we started using wordpress for our these fancy real estate websites we do and Each site we do it's a custom job every time They take like a year to make on average and every single client has their own very custom Needs and functionality and themes and all that stuff. So we do a site for somebody We'd build our own plugins and themes but just for that one client and it just existed just for them So after doing that for a while, we're like, you know Let's just build a plug-in that has at least the basics that are common on all of these sites And then on each of our sites we'll use this plug-in We'll just extend it with wordpress hooks and filters and things like that to make it custom for what that client needs But this being the internet things change over time And we definitely need a way to be able to update this core plug-in for all of our our clients But that kind of plug-in doesn't really work at least in my opinion in the publicly available WordPress plugins directory because it really only affects our our clients. So That comes to you know, what is an off-grid plug-in? What are we talking about here? So an off-grid plug-in. It's a plug-in that's not stored on wordpress.org But it still has all the neat features of one that is so most importantly this auto updating Also having robust information about itself pictures resources stuff like that And then why is an off-grid plug-in? Well in our case is a plug-in that just doesn't apply to the general public So it's only a subset of people who actually could use this thing people who use our plug-in They also have to have our back-end system that kind of drives the data So if a regular person just put this on their site, it wouldn't do anything for him another reason I think most people are interested in this sort of thing for is you want to sell a plug-in and so Saying you're not going to get that plug-in code unless you pay me 50 bucks up front that sort of thing And then have that plug-in able to update itself over time And a lot of the premium Commercial plug-ins out there do this like ACF pro does that gravity forms db. Migra pro all kinds of plug-ins that we pay money for and use on a ongoing basis they all have this kind of system in place to update themselves often with a check for Licensing keys and credentials and stuff like that to which we will touch on Another reason would be you want to violate wordpress's terms of service for whatever reason You may or may not know that every plug-in in their plug-in repository Has to be compatible with the gpl v2 license. Maybe yours isn't it's also being checked by actual real humans And thank God they are they keep the code quality up and make sure these plugins aren't doing weird things So if you want to make a plug-in, that's a new kind of YouTube video Embedder that's also mining Bitcoin in the background that's probably not going to fly on the wordpress directory so that's Another reason so how do you do this? Well, there are three steps The first step is you have to put together some kind of server that your plug-ins phone home to so Normally with a wordpress plug-in that server is the wordpress.org Plug-ins repository the page are all those publicly available plug-ins are so you have to kind of recreate a version of that for your own server When you are checking for updates in wordpress Wordpress is going to say is this the current version of that plug-in and it's got to get that info from somewhere That's centralized. So that's the first step is you need a server that has that information Available the second part is that in your plug-in you need to hook into wordpress to check it for updates So when wordpress runs its code to check all the plug-ins and see if they're up-to-date and that sort of thing it needs to be able to Check your plug-in and know what to do to know that that has its own plug-in server and how to to talk to that And then third you have to fake out wordpress with some bogus plug-in information and by this I mean that the process I'm talking about where wordpress sends information to its API Repository and gets that back and knows what to update what not to update all that data that it's sending the data It's getting back that only exists in that little part when you're hooking into it. It's Wild West stuff It's up to you to determine all that code for how am I going to talk to a server? How am I going to? Get that data back. There's no real standard for that in wordpress Right now you could just have a random number generator to tell if your versions up to date or not and wordpress would be cool with it So yes, there are indeed no standards with that So here is a visual just the process of how that that works So when you have this kind of off-grid plug-in I'm talking which by the way off-grid plug-in is a phrase I made up completely if you google that I don't think you'll get anything. I just thought it made sense So if you have something like this is checking its own server When wordpress tries to check for updates on plugins it will listen to your hook first and it will try to contact your Plug-in server for that information and bring it back to wordpress to let wordpress know I'm up to date or I'm not up to date And there's a couple hooks in there that are really small Site transient update plug-ins is the one that just checks if the version is higher or not than what you have already And then plug-ins API is the one there's another hook that actually shows When you view a plug-ins details in wordpress you like a little pop-up window thing that has all the Information about it how to install that sort of thing. That's an API hook that gets that information as well So it does any of your custom code first goes back to wordpress Then it runs it through for all the other plugins in one shot to API wordpress.org is what actually stores that information For regular plugins So there are a few solutions for this now. I found looking through this that there's really not a lot of information about this online Hence this talk hence the last two months of my life Part time so the first one I found is this quick and dirty solution that will cover And it's really just a real basic way to pull that off So if all you want to do is you know just have a plug-in and be able to update it But you're not worried about bells and whistles and all this stuff This is we'll go over it in just a moment. This this is a quick and dirty way to do it There's another way where if you're more comfortable with this keeping everything in like a wordpress kind of world That server part that I'm talking about Can be a wordpress site itself and that server can maintain all your plugins and information What's up to date? What's not and so all the wordpress sites out there running your plug-in? We'll talk to this wordpress server back and forth. We'll cover that There's also a great way if you're using the easy digital downloads plug-in and you got 200 bucks You can buy this software licensing extension, which if you are curious about writing a Commercial plug-in you want people to pay money for and keep it updated and have things like Product keys and stuff like that to make sure licenses are up to date This is totally the way to go in my opinion. It's all in wordpress. It's also where it's it's Wordpress server wordpress install you set up as a server And it is it is very very well put together my opinion and then the last way is my way Practicing for karaoke tonight So I went through kind of all these different solutions and and some other ones and I kind of came up with my own version that Not only keeps the code overhead down, which is important to me But also utilizes I was talking about there's a lot of Wild West stuff well, I've really tried to keep things as consistent as possible with Stuff that wordpress already does like all the stuff that you would do to write a plug-in for the plug-in Directory on wordpress.org to keep all that stuff the same and utilize that to fuel this process Is that further do it is code time? Not actually me writing a lot of code. I'm just gonna be looking at a lot of code So let me do a quick little magic trick on my computer here. All right Bingo, so The first thing we need to do of course when we're talking about plugins is we need some kind of plug-in to Use as an example. So I happen to write a little plug-in just for this It is called our matey and it will indeed make your website piratical by converting the letter R into a more C-worthy R And so let's give that plug-in a whirl here is a demo wordpress site And just some dummy content loaded in and if I hit refresh you will see oh oops I did not activate the plug-in activate the plug-in first. That's important Hop back over This way refresh There we go. That's more like it. However, I can see some flaws in this plug-in You know pirates are more sophisticated than this. They don't just say are they say other things too. They say I Also, this is just doing a blind search replace this Post-class link thing here. I look at that. It's replacing the HTML code. I'm not sure if you can see that But it's like er get equals underscore blank That's no good. So we should make an update to this plug-in and and let's push this thing out to everyone running this this Obviously premium plug-in. So the first thing we need to do here. I was going to show you the code now. This is just basically This one file this RMAT dot PHP is is really the whole whole plug-in And it's just doing this search replace thing and I have a variable for the version. Is that showing up alright? Yes, I can This way How's that? Alright, so, you know, I'm keeping track of the version and a couple other variables one thing that I do want to point out as well is that in this plug-in as in any plug-in that you would submit to the Real plug-ins directory. There's some information up at the top about this plug-in to some header Information about what the name is the URLs versions stuff like that and there's also a read me dot text file The read me file is used by the plug-ins directory to really supply all that stuff that you see on those plug-in pages, so the The description about it how to install it frequently ask questions. It's basically a markdown file and There is a lot of documentation on how to create this on the WordPress Online developer plug-in handbook, which is a fantastic resource So just want to make that note and keep that in mind. Alright, so back to our plug-in I am going to I've already put in the code here that will use this quick and dirty Method, let me just load that sucker up here so we can take a look at it This is just some person's github repo that they are trying to solve the same problem and they They put together this code. They have really two files One is a file that you include in your plug-in this WP auto update PHP You include that in your plug-in that tells your plug-in how to talk to this server thing And then they have the server thing which is what you set up on some URL out there And that is going to keep all the information on what the current version is and provide the latest file that sort of thing So real quickly, you know, you you would just include this file in your plug-in you would Say new class and you pass in some information of the current version the remote path That's the full URL to the server we keep talking about and some other information The plug-in slug License information if you want to do that and so on so that's the stuff that goes in the plug-in to make this connection now the server is just this like 30 ish lines of PHP code and You would just upload this somewhere on the web say updates dot army hearty comm or something And this one PHP file. It's very lean. It just has hard-coded in it It's going to receive a variable for Called action and if it has the word version come over it's going to spit out 1.1 And that's just typed out plus hard-coded in so that's that's as advanced as this kind of code is if it goes for info now info that's the one that has all the more detailed version of the Plug-in information so that has some more information that can be shown there And then lastly it just in this case if it doesn't get anything It's just going to spit out the zip file of this particular plug-in. So we have Done that here. We are including that file right there and we are instantiating it with the version of this and the full URL to the Plug-in server and then this tricky little plug-in base name underscore file thing. That's a little trick That's actually wordpress function plug-in base name to create What wordpress recognizes as the plug-in name for whatever file this is that you're you're in and I am in the plug-in file So that's how it comes out So now I've uncommented this code. Let's go and hit refresh in our admin area I have just hit refresh and nothing has changed and that is because Wordpress is smart and it caches all of its requests. It says, you know, I just checked for all Watch plug-ins are up to date like a couple minutes ago. I'm not going to check it again for I'm not quite sure how long the cash lasts like an hour or something so If you're in this situation and what it should have done is it should have shown that little update button So you can give wordpress a little kick in the pants and force it to update if you go to dashboard updates and Hit check again. It tells you the last time it checked and Voila now it is indeed making that connection to our server our server is talking back to it and it is telling it What the updated version is me hop back to our plug-ins page And then you get this familiar. Oh, there's a new version that's available. Hey, you know, let's check out the details I do want to check out the details. Let's hit that and so we'll see alright Well, there's the changelog and there's some information was last updated five days ago It's compatible with this and that's some that's pretty cool And that's all coming from that info request that's being set in the server now if I were to compare that to say Akismet like a real plug-in I Have a lot more stuff showing there. I've got banners I've got reviews and ratings and all kinds of crazy stuff a lot of these have screenshots and I want all of that But this little scrappy 30 line piece of code is not gonna do that But let's do the update. I was a little trick. I learned testing out my presentation where I got a close-out PHP storm for this to actually work so I will hit update now and Updated and you'll see right there version 1.1.0 and if I refresh here, you'll see that all of my ours A little more sophisticated now. Look we've got Gs and Hs And it says I so says Davey Jones at the bottom All right, well done. So that is just a real quick scrappy way to do that I want to make a quick note on versioning by the way So you'll notice that all of these plugins mine excluded that are real WordPress plugins have this like version, you know 1.1.1 kind of thing It's not like 1.0 or one dot fish or anything like that and they are actually all adhering to a standard called semantic versioning which is online at Semvair.org also a vocal exercise and This is important I believe that WordPress follows these rules But I know for sure that when it does the plug-in comparisons when it's comparing one version to another That it does use this criteria and so you might think oh, how hard could it be to compare some numbers? Well 2.1.0 is different than or 2.1.1 is different than 2.10.1 All right, which one would be higher which one would be lower if I'm a computer I don't know but it's following this pattern and Which actually corresponds to a PHP function Which is version compare And if you look in the WordPress code, it's just straight up using this PHP function which follows those rules and so We should all be using that versioning information as well So so that was the first example. I'm going to go to the second example now, which is our WordPress based solution so hold on here I'm going to just delete I have on my left here all of the plug-in files Which I'm deleting and I have a pre-loaded example 2 of the Second solution I will now copy these I should note too that example that we were just looking at the total file size With even with their included code that that example gave us with something like like 27k or 30k or something like that this next solution that we're looking at which also provides a file for you to include in your Your code to talk to its server and all that is a bit more It's it's bigger if I look at that it says it's 336k so it's an extra 300k or so on top of your whatever your other file size is which is kind of silly considering This is a 4k plug-in, but I think this is still worth checking out. So let's look at that Now it is only by coincidence that I even found the solution to be honest. You'll see that this plug-in Which this is this is so this is a plug-in that you install on a on a WordPress site that will become your plug-in server out there on the web and So you install this plug-in this plug-in was last updated three weeks ago It is pretty new to be honest. There's some bugs in it But it does work and so and it does have some nice features You can handle all the stuff in in a gooey admin interface. You can change the packages You can tap into another plug-in which is unrelated to this one called software license manager which can handle Licensing keys and things like that. You can also set it to pull your plug-in zip files from a remote source So Normally you would upload those files to the server But maybe you have a process where you're making your plug-in and it's all stored on github or Amazon or something like that So you could configure this to say pull those files straight from github when there's an update And it'll actually ping and check for updates and that sort of thing. So I already have this pre-loaded as well Which is this guy, and we just hit refresh here All right, so this is what the interface is this is just a plain vanilla WordPress install and I've added the plug-in And I've added a zip file of the updated version of my package So and you can see there says our matey is the package name and the version and you can hit a flag to require a license or not there are some various settings that you can change and And that is wonderful. I would note if you are going to really try this out though This looks like you would be able to upload a zip file, but you actually cannot at least I could not I If you try to upload it it will fail instead you have to follow their plan B Which is just upload a zip file to this location on your web server and and that does work fantastically well So that's that's all I did after I saw I just uploaded a zip file and called it good So you might start to ask yourself of all you did is uploaded this RMAT zip How does it know that the name is RMAT and the version is this and then so on and that is because this plug-in is So cool it is opening up that zip file behind the scenes and it's finding your plug-in header It's finding your readme.txt and it's pulling that data out and so it's pulling that out here as a summary But it's also displaying that information when you go to view those plug-in details in your real WordPress site So let's give that a shot. I'm just going to hit refresh here So again, I've replaced this plug-in code with code that is talking to that server And let me just briefly show you how that code looks So this is the updated version of this RMAT 1.0 and you'll see everything is exactly the same except for right here and this is the the code that is Once again, just loading the file that they're telling us to in their documentation They load this file in your WordPress plug-in and then it's making that request to tell it Hey plug-in, you know turn on and do your thing here's some information about me the plug-in I want you to I have my server at this URL and here's some information about my file name There's some weird stringer play stuff in here That's because I'm on Windows and there's a problem with that, but that's a bigger discussion This plug-in has has a bug with running on a Windows machine, which is the only reason there's some weird code right there But anyway, so you will see that it is saying it is recognizing that there is an update available so let's go ahead and It is also adding this check for updates link, which is kind of weird But I will hit update now after I close this because I've learned my lesson in practice alright update now and It does Indeed. Oh what? Well, it's supposed to update. I swear it did earlier today. So Yeah, there you go, there you go So I guarantee you that is a product of me being on on like running this on a local environment And probably a Windows thing But let's pretend that that worked and if I hit view details on this rendition of this. Oh, okay. Hold on. I Know what to do You want to hear a pirate joke? What happens when a red pirate ship runs into a blue pirate ship? Everyone gets marooned All right All right, let me hit refresh All right, I hit view details We'll see now There's some more stuff coming in and that's because this is indeed pulling that information from the read me dot text that we put Together now I should note I'm doing all the stuff in that read me dot text that I would do if it was in the plug-in directory Including I've made some pretty little banners and icons and things like that But those aren't showing up but a lot of stuff is Including let's see. I don't think yeah the screenshots one is not working on this So it seems to to work for everything except for graphical parts of this of this read me thing And I've I have tried many ways to get it to recognize those with without luck So that is another way that we can do this thing So let me pull up my third example here, which is the throw money at the problem solution and I again I highly recommend if you are doing a real deal commercial plug-in and you want to have license keys and keep track of that stuff Where you've only got updates coming through if someone's license is valid for a year and that sort of thing This is absolutely bar none the way to do it I'll I don't have a live example of this one to go through but from the I just know easy to do downloads is one of those Top gun plugins that that is amazing and it does indeed handle all of this you can kind of see the screenshots up there There's all these details on license and how to generate the licensing. There's an API. So say for instance you have After a payment completes on your site someone's actually bought your plug-in it can trigger an API thing that'll generate a new license And then that'll do something and then down here. Yeah handles renewals It also has yeah, there's different paths to upgrade for if there's you know different numbers of sites and for licensing It's very very detailed and then down here the part I was curious about is the it does add one click updates to your WordPress plug-ins Oh, and it supports themes too. So you could do this with a custom theme And again just like all the other code we've been looking at it does have this You include a line of code you pass in some information in your plug-in And that's it. It's real simple as the couple lines and it just goes Alright, so now let's talk about The final solution that I have in place which is the culmination of my journey with this Let me load up that example here So this one was You will note Again, we only have one extra PHP file In here, I do have this up on github. There's a link to it at the end for you all to use. It's all open source so you just have to include this one little file into your your plug-in and It is based on the work of this individual Who has really gone through? He starts by talking about stuff that sucks. That's wonderful, but he really dug into you know, what are All of the things that WordPress looks for what are all the hooks that in the details and the data that it can show On say like that little pop-up window that we're looking at and so it was really great to have this this reference So he's pointing out all the different little data points in his code And what was interesting is in his example? Oh, and he also explains the details of it too So for a list of contributors on the side of your plug-in information, you know What was interesting is that instead of a Server that which is a you know, it's all PHP all this stuff. He says you know, I forget the server I just need a JSON file living on the web somewhere And as long as I keep that JSON file up to date It'll know if my plug-ins up to date or not kind of like the very first solution We're looking at where things were kind of hard-coded in the version number and all that so I thought well That's very interesting. So I kind of took all of this stuff. We've been looking at and I've put together my own plug-in solution where on the on this side of things the WordPress site again, you just include the plug-in the Class file and you instantiate it with the version and the URL and this this basic stuff We've been looking at and there's one more step to hit run just because I I don't believe in having Classes just start messing around WordPress and unless you exactly tell them to and then on the server side I won't go in the code here But it really just does the same thing as that WordPress when we looked at where it looks at the zip files That or the zip file that you have for your plug-in it digs in there It pulls open the read me dot text and then it displays all that information To to the user and it as well. It also supports Those wonderful little icons and banners and things like that. So here's that's pretty small my apologies But I have a folder here for assets where you can upload banners and screenshots and that sort of thing I have another folder here for releases where you can have multiple versions of your plug-in of all time Which allows you it's also passing that version to WordPress. So it has some context of what previous versions were And so normally this would be called our matey zip here I have our matey 1.0.0 our matey 1.1.0 and so on and so on and so it's using that pattern to determine What the most recent version is and what file to to dig into so that's kind of the behind the scenes of it Let's see it in action. I'll hit refresh here and Again, if I hit view details now There we go We've got a galleon and we have all contributors. We have a donate link, please we have installation information and So on screenshots. We've got screenshots. It's like a real plug-in and it is so cool It tells you why you should update and even more if I go to this page over here Check again You know you want to update there we go. I get an icon It is so cool. All right, so let me close out of this jabroni and let's make a gamble on if it will work or not When I hit update Select all plug-ins. Do you believe? updated successfully Hooray, how's ah? alright, so There you have it. That is the Apologies It's a really important slide. I better get the right one up. Hold on. Come on, buddy. Not that one Everyone's seen my Tinder profile. Okay Everyone except my wife. Let's go Just kidding. All right so There are some further resources available. First of all, you can get these slides in a cross-platform PDF format and all of the files that I have including my Testish versions of all the different server sides of things on All here. It's just a link to a github Account there and that also includes a link to the my way version of the plugin update server and some documentation how that works updated at 1 a.m. Last night and Some other general details such as information on the semantic versioning the WordPress plug-in developer handbook Which I didn't show up here But it has all this great information on just all the stuff that you really should be doing for your plug-in if it were Gonna go in the regular directory including things like Image dimensions for those banners and icons and it supports SVG so it is my plug-in Readme specs There's a little shortcut to just generate a readme text file because they're very large and there's a lot of stuff in there So it's nice to nice to have a helping hand Oblucatory link to pirate jokes net which forgive me has not been updated in many years I hope you enjoy the flash header on that website And if you really want to get into the super geeky stuff You can actually see all of those individual data points that it That WordPress is using to make that little information modal window if you go into this file WP admin slash plug-in dash install that PHP and the function is called install plug-in information And it's got all the stuff listed out there. So there you have it I hope you found this useful and if you like this presentation My name is again is Mike Kirkus if you did not enjoy this presentation, then my name is Alex Vezquez Time some questions. What's that? Oh, certainly There you go. Anybody any questions? I'll have all left you all in amazement Or you're ready from Cam some karaoke. Yeah, I have not but That easy digital downloads one totally covers that situation that other WordPress one I a nice second solution here also covers themes as well and version updates and so on It's very similar just different function names You over there just to do it I would say for from this is a very selfish presentation because it's it's a problem I had to solve and in my case it's for a plug-in that applies to a bunch of people but not everybody So it didn't make sense to be on the public store But we're not charging people for the plug-in and because of that for us. We would rather have a more Programmy way to just upload a zip file to a server and forget about it as long as a zip file exists everything updates and plug-in Updates go out to everyone and so on so that works for us because we're not Asking people to pay for a premium plug-in, but if we were I would skip all this malarkey and just go with easy digital downloads One and and get that thing set up. Okay, so yeah, I guess even further more the question is is Doesn't do anything your plug doesn't do anything different. It's just leaner, right? Yeah, the overhead is almost zero with with mine, but doesn't support all the licensing keys and all that kind of stuff So it's a lot of extra features that are wonderful if you need them in easy to do the downloads. Cool Anyone else well, thank you very much. I think we have we have a wrap-up in what 10 minutes Yeah, 520 in the beach all right closing remarks. I'll see you at the beach