How To Create a WordPress Plugin from Scratch – Part 1

By | September 13, 2018

How To Create a WordPress Plugin from Scratch – Part 1

Download Our Free How To Use WordPress Guide, Plus Free WordPress Traffic Plugin Here: https://www.ultimateguidetowordpress.org

Transcript

00:00
hey what’s up guys Alex here thank you
00:01
for checking his video and welcome to
00:03
the episode number one of these brand
00:05
new series on how to create a wordpress
00:07
plugin from scratch
00:12
[Music]
00:21
welcome again in this first tutorial
00:23
we’re going to take a look on all the
00:25
basics to setup our first amazing plugin
00:29
in our beautiful wordpress installation
00:31
before starting because we are coding
00:34
and we’re going to code a lot of
00:36
different things remember to set your
00:39
wp-config.php file in your root
00:42
directory installation of wordpress we
00:45
define the WP debug global settings to
00:49
through if it’s not set to true every
00:52
time you have an issue or every time you
00:55
write something wrong like a bad PHP
00:57
code or something like that your entire
00:59
website is just not gonna print you’re
01:01
gonna see a blank page we don’t want
01:04
that because we’re under development so
01:05
we need to get all the debug information
01:08
possible all the information that we
01:10
need to understand what we did wrong and
01:13
how to fix our code so just remember
01:15
this is the only requirement that you
01:17
need for like to follow this tutorial
01:19
set your WP debug to through okay let’s
01:23
get started if we access the
01:25
installation like a regular WordPress
01:27
installation this is the usual structure
01:30
like folder structured are you gonna see
01:32
and as I said at the very first lesson
01:35
of the WordPress 101 the only folder
01:38
that you should care about your
01:40
WordPress installation is the WP content
01:42
everything else all the files WP admin
01:44
that will be includes you should never
01:46
touch those files because those are part
01:48
of the core installation of WordPress so
01:51
by accessing the WP content you’re going
01:53
to have a list of all the folders that
01:55
you can use and you can touch in order
01:57
to create your custom things and I’m
01:59
sure you already guessed that we need to
02:01
create our plugins in the plugins folder
02:03
by default WordPress comes with a
02:06
cassette and Hello Dolly to pre install
02:09
plug-in it they show like a pretty
02:11
regular structure and then the usual
02:13
index dot PHP with an empty comment just
02:17
to avoid the direct axis of the this
02:21
folder there at access of these files if
02:24
the user gains access to your WordPress
02:28
installations through a browser so let’s
02:30
start by creating a new folder and let’s
02:32
name the folder
02:33
with the same name that we want to
02:34
assign to our custom plugin so in my
02:36
case is going to be Alec add – plug in
02:41
something like that and the requirement
02:45
the kind of the only requirement of
02:47
WordPress on how to about creating a
02:50
plug-in is having a unique name for your
02:52
plugin and these unique name has to be
02:54
carried around from the folder to the
02:56
main PHP file if this name is not unique
03:00
your plug-in will have some conflicts of
03:03
updating or versioning with other
03:05
pre-existing plugins so before creating
03:08
your folder name just do a check inside
03:11
the official plugins repository just
03:14
click add new and search for the plug-in
03:17
name that you want to create so in my
03:19
case is going to be a lake add plug-in
03:21
and see if we have any results no
03:24
matching result so that’s perfect that
03:26
plug-in name doesn’t exist and I am safe
03:29
it to use it let’s access this folder
03:31
and let’s open this folder in sublime
03:33
text inside our newly generated plugin
03:36
folder the first file that we need to
03:38
create is a PHP file with the same exact
03:42
name of our plug-in folder so in my case
03:45
is alak add the – plug-in dot PHP and it
03:51
is really important because by default
03:54
WordPress does this wordpress checks all
03:57
the folders inside your plugins
04:00
installation and the text the PHP file
04:03
that has the same name of your folder
04:06
and automatically lists all those things
04:08
inside your plug-in directory but of
04:10
course having an empty file is not
04:12
enough for WordPress to recognize that
04:14
this is a plug-in and you want it to be
04:16
listed in your plug-in directory so
04:18
let’s create let’s open the PHP tags and
04:21
as usual because this is just a PHP file
04:24
we’re not going to have any HTML written
04:26
here we can avoid you close the tags and
04:28
this is actually really recommended not
04:31
closing tags then we define a global
04:34
setting for our package and say that
04:37
these is a package called
04:41
alak add plug-in something like that and
04:45
now we need to define some global
04:47
settings in order for wordpress to
04:49
recognize our plugin and these section
04:52
is pretty much identical to the comment
04:56
section that you write in your style dot
04:58
CSS when you generate a new theme to
05:00
give the wordpress the ability to
05:02
recognize the theme and specify some
05:04
unique attributes to customize the theme
05:07
so we’re going to do exactly the same
05:09
let’s open again our comment block and
05:12
don’t use inline comment but use comment
05:15
block that’s really important and let’s
05:17
write the first is the plug-in name
05:20
attribute and remember to write it
05:22
exactly as I do otherwise WordPress can
05:25
not recognize that specific attribute
05:27
and the plug-in name is Alec add plug-in
05:30
oops
05:31
plug-in then the second attribute is
05:34
plug-in you are I and no URL if you are
05:40
I and here we need to specify the unique
05:44
URL of that plug-in in my case it’s
05:46
going to be just simply HTTP slash slash
05:48
Alec add calm but whatever if you have
05:53
your plug-in hosted on a city file or on
05:55
a github repository you can set up that
05:58
specific URL so if for example I have
06:01
this plug-in in a subdirectory of my
06:05
website I can specify a unique
06:07
subdirectory so if they click to view
06:10
more details about my plug-in they’re
06:12
going to get redirected to that specific
06:14
URL the third parameter is description
06:17
and we can write simply this is my first
06:22
attempt on writing a custom plugin for
06:28
these amazing tutorials series something
06:32
like that do we like it I guess so and
06:34
here you can write HTML just really
06:38
simple HTML you can have like strong
06:40
bold italic underscore like underline
06:44
all this kind of stuff like really
06:46
really simple HTML don’t use like crazy
06:49
HTML markups are not recognized then we
06:52
need to specify the version and my
06:53
version is the 1.0.0 then we need to
06:56
specify the author the author is
06:59
alessandro
07:01
double-quote Alec had castellani is my
07:05
name and then the author URI also in
07:09
this case and this is gonna basically
07:12
redirect the user whenever they click on
07:16
the name or the author of the plugin so
07:19
in this case on my name then you need to
07:21
specify the license of this plugin and
07:23
usually the plugins are all open-source
07:26
license like releasing a plug-in on
07:28
WordPress on your future repository of
07:30
WordPress that is not open source is
07:32
really hard I don’t think it’s like
07:34
recognized of stuff like that is like
07:37
not allowed to publish a plug-in that is
07:40
not under open-source license so usually
07:43
when you’re building a plug-in always
07:45
set at GPL v2 or later that’s my kind of
07:50
my favorite open-source license
07:52
otherwise there’s like apache license
07:54
MIT license just check in the new
07:57
official documentation to see which
07:59
license matches properly your needs and
08:02
just use that and then we need to
08:04
specify liking the theme the text domain
08:06
of our plug-in in my case is going to be
08:08
other CAD plug-in I’d save it let’s go
08:12
back in our WordPress installation let’s
08:15
access our plug-in directory let’s
08:17
refresh and look what we have here that
08:20
is pretty amazing right we have Alec hat
08:23
plug in the description the link to
08:26
click visit the plug-in side and if we
08:29
visit the plug-in side we’re going to go
08:30
to these fake URL that doesn’t exist I
08:33
like add slash plug-in I don’t have
08:35
anything but it goes to my website and
08:37
if I click on the my name it goes
08:42
actually to my website so I click on the
08:44
other name and then we have the version
08:45
and we have by default all the native
08:48
links of WordPress of a plug-in so to
08:51
activate edit or delete the plug-in and
08:54
of course if we click Edit WordPress
08:56
automatically goes inside the editor of
08:58
the plug-in lists all the files that we
09:00
have here so we could potentially also
09:02
write our own Pauline directly inside
09:04
WordPress but that would be kind of
09:06
crazy right and of course if we try to
09:08
activate it it’s gonna be activated but
09:11
there’s pretty much nothing here
09:14
because we didn’t write anything so we
09:16
can activate and deactivate the plug-in
09:17
and nothing is going to break our
09:20
website to work if i refresh I’m using
09:22
the latest 2017 theme of WordPress and
09:26
nothing is happening because of course
09:28
it’s an empty plugin but hey we few
09:31
lines of code we generated a pretty
09:34
legit first plug-in installation isn’t
09:37
that great the last thing that I want to
09:39
do before concluding this first episode
09:41
is screening a really important and
09:43
really necessary file in order to have a
09:46
little bit of security in your plugin
09:48
and this file is the standard index dot
09:51
PHP inside your installation because if
09:55
someone tries to access directly your
09:57
plug-in folder it will not go into all
10:02
the available files that you have
10:04
because you cannot access and see all
10:06
the files but it will be redirected just
10:08
in case that happens it will be
10:10
redirected to the index file and in the
10:12
index file what we want to do you want
10:15
to just print an empty PHP we’d silence
10:19
is golden and is the same technique used
10:24
in another PHP file here like in the
10:26
index dot PHP in the default plugins and
10:30
if you know this it’s also in the index
10:32
dot PHP in the wp-content folder and
10:35
that’s how wordpress deals like in a
10:38
super quick and dirty way unlike direct
10:41
access into folders that we don’t want
10:43
to really give to read access to it
10:45
because it’s kind of catchy right the
10:47
last thing that you could do you could
10:49
simply in the main PHP file of your
10:53
plug-in just print right after the basic
10:56
attribute of your plugin just by leaving
10:58
an empty row the license that you’re
11:01
actually using and I grab these license
11:03
directly from the new website and the
11:05
license that is described here is GPL
11:08
version 2 this is not 100% required
11:11
especially when you’re building a
11:13
plug-in but it’s it’s absolutely
11:15
required if you decide in the future to
11:17
publish your plug-in into the WordPress
11:20
official plugins repository so why not
11:23
put in it by default as the first thing
11:26
so we will
11:27
not forget in the future and that’s
11:28
pretty much it this is the very first
11:31
and very very simple video about the
11:33
plug-in development series in the next
11:35
video we’re going to spend a little bit
11:37
of time on tackling all the security
11:40
precaution and safety precaution in
11:43
order to start developing a plug-in
11:45
without worrying too much of exposing
11:48
vulnerabilities or leaving backdoors
11:50
open to our WordPress installation or
11:53
whatever the WordPress installation
11:54
we’ll use our word plug-in so next
11:57
lesson is going to be way more awesome
11:58
than this one I really hope so well it’s
12:01
pretty much it for this video hope you
12:02
enjoyed if you did please give it a
12:04
thumbs up or subscribe to my channel and
12:06
if you want you can spend a couple of
12:08
minutes on the support me page of my
12:09
website where you can find all the
12:10
different ways and methods to support me
12:13
support my channel and help me to do
12:14
better videos and better tutorials for
12:16
you thank you again guys and until the
12:18
next lesson has usual happy coding

 

CLICK HERE TO READ MORE ABOUT:  Use Google Drive Photos and Files in WordPress Media Library

Have a great day!

 

free website traffic

 


If you have any question feel free to leave in the comment section below. Thanks for watching and stay tuned

 

 

Facebook Comments

how to use wordpress

 

Leave a Reply

Your email address will not be published. Required fields are marked *