The WordPress plugin Development series
Before starting if you’re a new user if you’re the first time and you’re really interested in starting WordPress Plugins Development.
Please stop there if you don’t know how to build a custom theme from scratch.
If you don’t know how WordPress works , we’ll go inside the settings API or all the stuff that you need to do to build a custom WordPress mega menu.
If you’re completely basic, if you’re a total beginner you don’t know.
What you’re doing just starts with the premium development to learn how to build a pretty cool theme and then continue with the WordPress mega menu series.
where we –start doing some object oriented programming code to touch the wall kernel class and build a custom theme.
if you follow all those series or you’re an experienced developer you just want to learn how to build plug-in you’re in the perfect place.
So what are we going to do in this Session, we’re going to just take a look at how to build a plug-in and how to let WordPress recognize our plugins.
we’re going to take a look at the regular hooks of WordPress to handle activation, deactivation and deletion of plug-in and tap the database.
So let’s learn and spend a little bit of time to know how to do things properly. How to do the plug-in is pretty quick.
we’re not going to spend too much time on it but building different types of plugins.
And using object-oriented I mean to build different types of plugins. It’s really interesting.
so you really need to know your basics and you really need to know WordPress and all the object-oriented programming stuff for WordPress.
Because those are really important without those basic knowledge pieces or without that basic understanding of object-oriented programming in PHP.
It’s going to be really hard for you to follow these series so I’m super excited and super pumped to start this session.
Let’s learn how to code and just that’s okay we’re gonna have a lot of fun and usually if you like this quick introduction about this amazing session that you’re going to start.
The next first amazing lesson of plug-in development is serious happy coding.
Welcome to the one of these brand new series on,
How to create a WordPress plugin from scratch?
Welcome again in this first tutorial of WordPress Plugin Development.
we’re going to take a look at all the basics to set up our first amazing plugin in our beautiful WordPress installation.
Before starting, set the wp-config.php file in your root directory installation of WordPress.
We define the WP debug global settings to through.
If it’s not set to true every time you have an issue or every time you write something wrong like a bad PHP code.
your entire website is just not gonna print, you’re gonna see a blank page.
we don’t want that because we’re under development so we need to get all the debug information possible and all the information that we need to understand.
what we did wrong and how to fix our code so just remember this is the only requirement that you need for like to follow this tutorial set your WP debug to through.
Let’s get started if we access the installation like a regular WordPress installation this is the usual structure like folder structured.
You should care about your WordPress installation is the WP content everything else all the files.
WP admin that will be includes you should never touch those files because those are part of the core installation of WordPress.
So by accessing the WP content you’re going to have a list of all the folders that you can use and you can touch in order to create your custom things.
We need to create our plugins in the plugins folder by default WordPress comes with a cassette and Hello Dolly to pre install plug-in it.
They show like a pretty regular structure and then the usual index dot PHP with an empty comment just to avoid the direct axis of the this folder.
There at access of these files if the user gains access to your WordPress installations through a browser.
Creating a new folder
So let’s start by creating a new folder and let’s name the folder with the same name that we want to assign to our custom plugin.
So in my case is going to be Alec add – plug in something like that and the requirement the kind of the only requirement of WordPress.
On how to about creating a plug-in is having a unique name for your plugin and these unique name has to be carried around from the folder to the main PHP file.
If this name is not unique your plug-in will have some conflicts of updating or versioning with other pre-existing plugins.
So before creating your folder name just do a check inside the official plugins repository just click add new and search for the plug-in name that you want to create.
So in my case is going to be a lake add plug-in and see if we have any results no matching result.
So that’s perfect, that plug-in name doesn’t exist and I am safe it to use it.
Let’s access this folder and let’s open this folder in sublime text inside our newly generated plugin folder.
The first file that we need to create is a PHP file with the same exact name of our plug-in folder.
So in my case is alak add the – plug-in dot PHP and it is really important because by default WordPress does this.
WordPress checks all the folders inside your plugins installation and the text.
The PHP file that has the same name of your folder and automatically lists all those things inside your plug-in directory.
But of course having an empty file is not enough for WordPress to recognize that this is a plug-in and you want it to be listed in your plug-in directory.
So let’s create
let’s open the PHP tags and as usual because this is just a PHP file we’re not going to have any HTML written here.
We can avoid you close the tags and this is actually really recommended not closing tags.
Then we define a global setting for our package and say that these is a package called alak add plug-in something like that.
And now we need to define some global settings in order for WordPress to recognize our plugin.
And these section is pretty much identical to the comment section that you write in your style dot CSS.
When you generate a new theme to give the WordPress the ability to recognize the theme and specify some unique attributes to customize the theme.
So we’re going to do exactly the same let’s open again our comment block and don’t use inline comment but use comment block that’s really important.
Let’s write the first is the plug-in name attribute
Otherwise WordPress can not recognize that specific attribute and the plug-in name is Alec add plug-in.
OOPs plug-in then the second attribute is plug-in you are I and no URL if you are I and here we need to specify the unique URL of that plug-in in my case .
It’s going to be just simply HTTP slash slash Alec add calm but whatever if you have your plug-in hosted on a city file or on a github repository.
You can set up that specific URL so if for example I have this plug-in in a subdirectory of my website I can specify a unique subdirectory.
So if they click to view more details about my plug-in they’re going to get redirected to that specific URL the third parameter is description.
Arranged: Otherwise WordPress can not recognize that specific attribute and the plug-in name is Alec add plug-in.
OOPs plug-in then the second attribute is plug-in you are I and no URL if you are I and here we need to specify the unique URL of that plug-in in my case.
It’s going to be just simply HTTP slash slash Alec add calm but whatever if you have your plug-in hosted on a city file or on a GitHub repository.
You can set up that specific URL so if, for example, I have this plug-in in a subdirectory of my website I can specify a unique subdirectory.
So if they click to view more details about my plug-in they’re going to get redirected to that specific URL the third parameter is description.
And we can write simply this is my first attempt on writing a custom plugin for these amazing tutorials series. Something like that do we like it I guess so and here you can write HTML just really simple HTML you can have like strong bold italic underscore like underline.
All this kind of stuff like really really simple HTML don’t use like crazy HTML markups are not recognized.
We need to specify the version and my version is the 1.0.0 then we need to specify the author the author is Aless double-quote Alec Had Castellani is my name.
And then the author URI also in this case and this is gonna basically redirect the user whenever they click on the name or the author of the plugin. So in this case on my name then you need to specify the license of this plugin and usually the plugins are all open-source license like releasing a plug-in on WordPress.
So usually when you’re building a plug-in always set at GPL v2 or later.
Otherwise there’s like apache license MIT license just check in the new official documentation to see which license matches properly your needs.
And just use that and then we need to specify liking the theme the text domain of our plug-in in my case is going to be other CAD plug-in I’d save it.
Let’s go back in our WordPress installation.
Let’s access our plug-in directory, refresh and look what we have here; that is pretty amazing, right? We have Alec Hat Plug. If I click on my name, it goes actually to my website, so I click on the other name, and then we have the version, and we have, by default, all the native links of WordPress for a plug-in.
So, to activate, edit, or delete the plug-in, and of course, if we click Edit, WordPress automatically goes inside the editor of the plug-in, lists all the files that we have here. So we could potentially also write our own code directly inside WordPress, but that would be kind of crazy, right?
And, of course, if we try to activate it, it’s gonna be activated, but there’s pretty much nothing here because we didn’t write anything. So we can activate and deactivate the plug-in, and nothing is going to break our website. If I refresh, nothing is happening because, of course, it’s an empty plugin.
Before concluding this first lesson, screening is a really important and necessary file in order to have a little bit of security in your plugin. And this file is the standard index.php inside your installation because if someone tries to access your plugin folder directly, it will not go into all the available files that you have. You cannot access and see all the files, but it will be redirected just in case that happens. It will be redirected to the index file, and in the index file, what we want to do is print an empty PHP.
Index.php is the default plugin if you know this; it’s also in the index.php in the wp-content folder. That’s how WordPress deals with direct access into folders that we don’t want to give read access to because it’s kind of sketchy, right?
The last thing that you could do is simply in the main PHP file of your plugin, just print, right after the basic attributes of your plugin, by leaving an empty row, the license that you’re actually using. I grabbed this license directly from the new website, and the license that is described here is GPL version 2. This is not 100% required, especially when you’re building a plugin, but it’s absolutely required if you decide in the future to publish your plugin into the WordPress official plugins repository. So why not put it in by default as the first thing, so we will not forget it in the future.
About the plugin development series, in the next lesson, we’re going to spend a little bit of time on tackling all the security precautions and safety precautions in order to start developing a plugin without worrying too much about exposing vulnerabilities or leaving backdoors open to our WordPress installation or whatever the WordPress installation we’ll use our plugin. So the next lesson is going to be way more awesome than this one, I really hope so.
Well, it’s pretty much it for this lesson. Hope you enjoyed it. If you did, please give it a comment below by filling up the form. If you want, you can spend a couple of minutes on the support page of this website, where you can find all the different topics and awesome blogs on that topic.
Thank you again, guys, and until the next lesson, as usual, happy coding.
Add a Comment
You must be logged in to post a comment