Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Pluggable functions are a set of functions built into WordPress. While there are many functions in WordPress, pluggable functions are special because they allow you to override them, essentially adding new functionality into the built-in workings of WordPress. All that's necessary to override pluggable functions is to create a new function with the same name. All the pluggable functions are located in wp-includes, pluggable.php file. It's a good practice often, when you are going to override a pluggable function, to start with the original pluggable function from the pluggable.php file.
What I am going to do is I am going to create a new plugin here called welcome.php. This is going to override the wp_new_user _notification pluggable function, which sends a message whenever a new user registers at the site. This way I can customize the message that gets send to the user, so they get the message that I want them to see. So, in the plugins directory, I've created a new file called the welcome.php. I've put in all my plugin comments, and I am ready to go. So, now I am going to go into the pluggable.php file. I am going to find that function, wp_new_user_notification.
I am going to copy this as it stands directly from the pluggable.php file, and I am going to paste it directly into my plugin file. Now that I've pasted this function into my plugin file, I simply need to override the function and change it how I want to. Most of the functionality I want to remain the same. Notice I am sending a mail to the administrator here. I don't need to change that, but I do want to change the message that's going out to the new user, which is located here.
A couple things so you don't get scared: They're using an sprintf function, which essentially allows you to replace parts of your string with the variables that you pass in-- it's simply a secure way of doing dynamic variables replacement. In addition, they have this underscore, underscore function, which we'll talk about later when we get into the internationalization. So for now, let's go ahead and create our message variable, and we are going to write some new information in here. So, I am going to use the same function that they use, in case we want to internationalize this down the road. And I am going to change this to say, 'Welcome to mmmStuff.com,' which is my blog name.
And then I am going to add some new lines, returns, and I am going to add another line. I am going to use the same methodology that they are using, which is the dot equals, and I am going to do that for the original one as well. What that does is that says, "Set this message equal to whatever is already in this variable plus whatever comes after the Equal sign," which is going to be a new part of the message, which will say, 'Here is your information for future reference.' And again, a couple of new lines, and one final line signing out, and this one will simply say, 'Feel free to come back and check on stuff often'.
So there is my new message. In order to make this function work, I simply need to activate the plugin; however, I need to be careful because in some instances, the original plugin may have already been activated because of the order of inclusion. So I need to put a special if statement that will wrap around it, and this is exactly what you'll see in the plugin.php file. I'll say not function_exists, which determines whether or not the function exists. So, if it doesn't exist, then it will go ahead and create it; otherwise it will simply ignore this piece.
So, we're going to copy our function name, paste it into here, and then make sure we close both of them. Eclipse has a special feature: if you highlight everything and hit Command+I, it'll automatically clean up your indentation. So that's an easy way to do that. So now we can save it, and we can go into our admin, and you'll see on your Plugins page your Welcome Plugin has been parsed. If we activate it, it should go through and set up that function so that the next user who registers at the web site will then be able to get your new message.
In order to enable registration at the web site, by default, WordPress has it turned off so that not everyone can register. So, we are going to go ahead and select this so that anyone can register, save the changes, and then we are going to go ahead and log out, and sign in as a new user. So, if you go to the beginning of your web site, the front page, you'll see there is a link here to register. If we click this, we'll have the option, and you can choose whatever username you want, and then enter your e-mail, and click Register.
That will then call our function, that wp_new_user_notification. Checking your e-mail. So you can see I got a welcome e-mail, Welcome to mmmStuff.com. Here is your information for future reference. It has my username and password, the URL to the web site, and then "Feel free to come back and check on stuff often." WordPress has a set of built-in functions called pluggable functions that can be overridden by plugin developers. Because these functions are called on from within WordPress and other plugins, it allows us to be able to override the default functionality, and have things work a little differently, however we may choose.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 96875 Viewers
56 Video lessons · 110571 Viewers
71 Video lessons · 79404 Viewers
131 Video lessons · 38092 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.