Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
In this video we look at how to tie into the Gravity Forms plugin using their available hooks.
-
0:00
In this video, we're going to look at how to figure out if a plugin has a hook, and
-
0:05
then if it does, how we would add that to our own code.
-
0:08
We're going to start with the popular plugin, Gravity Forms.
-
0:13
And I'm simply gonna search for Gravity Forms hooks.
-
0:18
We can see that we're being linked to developer documentation,
-
0:22
which is a good sign.
-
0:24
As I mentioned earlier,
-
0:25
just because a plugin exists, doesn't mean that it has a hook.
-
0:30
And just because a hook exists, doesn't mean that it's documented.
-
0:35
In the case of Gravity Forms, we get all of these in place and
-
0:39
we can see easily here are the hooks and filters.
-
0:43
I'm going to come down and look at one specifically in
-
0:47
example, which is the gform_submit button.
-
0:54
We can see that this is a filter.
-
0:57
And we can see some code for how it's being executed.
-
1:01
And if we scroll down we can see an example.
-
1:07
What this example is showing us is, the name of the hook,
-
1:12
our example function, the priority, and then the parameters.
-
1:18
We can see that we're defining this function,
-
1:20
here that's gonna be our custom function.
-
1:23
We're getting fed the button, itself.
-
1:26
And then we're getting fed the form.
-
1:29
So, we have the data about the button, and
-
1:32
we have the data about the form that's being submitted.
-
1:35
And we can see, because it's a filter, we have to be returning something.
-
1:39
And what we're returning is the full html object here.
-
1:44
So in this particular case let's say that we were working with something that
-
1:47
was Bootstrap based, or
-
1:49
something that had the class of btn in their buttons and not button.
-
1:55
All we would have to do is simply update the class we wanted.
-
1:59
And then, if maybe we wanted to change the text,
-
2:05
in any sort of way, we could do that.
-
2:07
And then we could save it all as a string and have it returned.
-
2:11
This would be a simple way that we could update the button text,
-
2:14
or the code behind it in gravity forms.
-
2:18
Something else that's interesting about this example,
-
2:21
is not only can you apply your function to all buttons.
-
2:26
However if you add underscore and then the ID of the form that you're working with,
-
2:32
you could actually apply a function to filter just that submit button for
-
2:37
that particular form.
-
2:39
So this is a good example of good documentation and
-
2:43
good hooks that we could tie into.
-
2:45
Gravity Forms really was built in a great way for other developers to add onto it or
-
2:50
hook into it.
You need to sign up for Treehouse in order to download course files.
Sign up