Viewers: in countries Watching now:
In WordPress: Creating Custom Widgets and Plugins with PHP, Drew Falkman teaches PHP developers how to create custom functionality for WordPress 2.0 through 3.0 using widgets and plugins. This course starts by installing and setting up WordPress 3.0 on both Mac and Windows, then provides an in-depth look at tasks related to these WordPress add-ons: installing and administering, building and customizing, creating editable options and database tables, working with posts and pages, and utilizing jQuery and AJAX. There are also tutorials dedicated to promoting a widget or plugin, adding security, and localizing the interface. Exercise files are included with the course.
A lot of times plugins are going to require some sort of configuration options. They might require that the site administrator enters something in order that they work properly. For example, if you use some remote service like Twitter or Flicker or Rhapsody, you are going to need their authentication information to go out and get their data. If this is a case with your plugins, you're probably going to want to create an admin interface that plugs directly into WordPress's built-in admin interface. There are three basic steps to do that: The first is we are going to create a function that outputs the user interface, and the second we're going to write another function that uses one of many functions to create a link inside of the Admin menu.
The last thing is we are going to use a hook to tie this in. So let's start at the beginning and write a function that's going to output our Options page. So we'll call it cccom_option_page. I like to give a prefix like cccom whenever I am using functions to keep from collision--that is, interfering with other functions in the WordPress environment. So in here is going to be user interface. So I am going to close the PHP that's opened at the top of the page, and I am just going to open another one for the rest of the page.
That way, in between, I can just use straight HTML. So I am going to create a div first and use the wrap class, which is just a built-in style inside of WordPress. Then I am going to use the special function called screen_icon, which will output the special icon from whichever of the admin items is currently being viewed. I will create a little header, and I will create a quick description.
So I am basically going to say, "Welcome to the CC Comments plugin. Here you can edit the e-mail(s) to CC." All right, it's a dangling preposition, but we're not going to pick nits here. So that's a basic function; it outputs a really basic UI. Like I said, we'll add the input fields in the updating process later. Then we want to create another function, and this function is going to register with the Admin menu.
There are a number of different functions available, which we will explore in a later video. For this one, we are going to add it right into the Settings options. So we are going to use a special function called add_options_page, and then we are going to pass the page title. We are going to pass what we want to see in the menu. We are going to pass the capabilities. This is essentially the roles from the user information.
WordPress has a bunch of information on the Codex about the different types of capabilities there are. It lists them all, and you can see which ones apply to whom and what they mean exactly here. Let's just set it to Manage Options. Then we are going to add a special menu slug that's essentially going to be like an ID for the menu item. So we'll call it cc-comments-plugin. And the last thing we'll add is a link to the function that generates the page, which is this one here. So let's go ahead and copy it.
I often have typing problems, so I like to just copy and paste when I can. So this will register that item with an Admin menu. So the last thing we need to do is make sure that this function gets called for the right hook. So add_action-- should look familiar by now--called admin_menu, and it's going to call this function right here. So that's all it takes. We added this action, which when it generates the admin menu, WordPress will then call this function, which will add this information to the Options portion of the administrator.
When the user clicks on it, it will then call this function, which will open this and use this to generate the screen. So let's see how that looks. So here is our WordPress dashboard. Right now, I don't have any link in here, so let's go ahead and refresh it. You can see now I have the CC Comments down here. When I clicked on it, it called the CC Comments Options, and it said, "Welcome to the CC Comments plugin." Notice this is what I got from the screen icon. So you can see it adds it under the Settings menu-- that's because I use Add Options page-- and then it generated this page, and it used the screen icon to generate this.
If I were to move this to a different section, it would use the appropriate icon. That's why that's a great and helpful function. Many WordPress plugins require that the administrator does some kind of adding in order for it to work. Creating your own page in the WordPress admin is a matter of writing a function that will output the page, writing another function that's going to place a link into one of these menus, and then finally adding a hook into an admin menu.
Find answers to the most frequently asked questions about WordPress: Creating Custom Widgets and Plugins with PHP .
Here are the FAQs that matched your search "" :
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.
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.